android studio has hidden elements in activity - android-studio

|I just added new activity (chose settings template) when i created my app in my setting page there are some elements that aren't exist in my editor nor in xml code.
Screenshots
In App
In Editor
Code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/settings">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="4sp"
android:layout_marginRight="4sp"
android:weightSum="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioGroup
android:id="#+id/appLang"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="35dp"
android:layout_marginEnd="35dp"
android:layout_marginRight="35dp"
android:layout_marginStart="35dp"
android:layout_marginLeft="35dp"
android:orientation="horizontal">
<TextView
android:id="#+id/applangtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/applangtextstring" />
<RadioButton
android:id="#+id/radio_indo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:text="#string/indoLang" />
<RadioButton
android:id="#+id/radio_english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:text="#string/englishLang" />
</RadioGroup>
<RadioGroup
android:id="#+id/learnLang"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="35dp"
android:layout_marginEnd="35dp"
android:layout_marginRight="35dp"
android:layout_marginStart="35dp"
android:layout_marginLeft="35dp"
android:orientation="horizontal">
<TextView
android:id="#+id/learnlangtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/learnLangText" />
<RadioButton
android:id="#+id/learn_radio_indo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButton2Clicked"
android:text="#string/indoLang" />
<RadioButton
android:id="#+id/learn_radio_english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButton2Clicked"
android:text="#string/englishLang" />
</RadioGroup>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Any idea?

Solved
There was some extra lines in my settingsActivity file in ocCreate() function after removing them and rebuild my app UI issue was solved.
My current onCreate() function is like this now:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
// here was some lines regarding to Topbar
}
Note: what was connection between topbar(toolbar) and UI issue
personally i don't know but my problem solved after removing that and
that's all matter :)

Related

Android Studio: How to put a Recycler View under a TextView

I'm trying to put a recycler view under a textView. In the design view, the arrangement of the objects is how I want it:
But in the emulator the activity is shown like this:
That is, above are the two textViews and below are the recyclerViews.
But I want: textView - recyclerView - another textView and at the end another recyclerView
This is the code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".richieste.CronologiaRichieste">
<LinearLayout
android:id="#+id/row1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/acquistiText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ACQUISTI"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:textSize="#dimen/dim_testo"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/acquisti"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
android:scrollbarStyle="outsideInset"
android:layout_weight="1"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" />
<TextView
android:id="#+id/venditeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VENDITE"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:textSize="#dimen/dim_testo"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/vendite"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
android:scrollbarStyle="outsideInset"
android:layout_weight="1"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" />
</LinearLayout>

How can I align RadioButton and TextView horizontally?

See the image... If I don't Use the RelativeLayout the output is TextView
is below RadioButton
If I use the following code to align radioButton and TextView horizontally, the radioButtons are not identified as a part of RadioGroup, which leads to multiple selections.
<RelativeLayout
android:id="#+id/relative_layout_1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView3">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:drawableLeft="#drawable/laptop_for_gaming"
android:text="#string/gaming" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/radioButton3"
android:text="#string/gaming_desp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/radioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/laptop_professional_use"
android:text="#string/business_use" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/radioButton4"
android:text="#string/business_use_desp" />
</RelativeLayout>
</RadioGroup>
</RelativeLayout>
And if I don't use the RelativeLayout they are not align horizontally instead they are one below the other.
you can use android:orientation="horizontal" on your RadioGroup
You have to close your radiogroup adding </RadioGroup> after the RadioButtons :
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView3">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:drawableLeft="#drawable/laptop_for_gaming"
android:text="#string/gaming" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/radioButton3"
android:text="#string/gaming_desp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp">
<RadioButton
android:id="#+id/radioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:drawableLeft="#drawable/laptop_professional_use"
android:text="#string/business_use" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/radioButton4"
android:text="#string/business_use_desp" />
</RelativeLayout>
</RadioGroup>

how to connect two layouts in eclips

I'm beginner in Java Android developing. i have two XML file in res/layout/. named activity_fast_tip.xml and activity_setting.xml i can't connect these two component together. in activity_setting.xml
#Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView(R.layout.activity_fast_tip);
tipPctTextView=(TextView)this.findViewById(R.id.tipPctTextView);
tipAmountTextView=(TextView)this.findViewById(R.id.tipAmtTextView);
totalAmountTextView=(TextView)this.findViewById(R.id.totalAmtTextView);
calcTipAmountButton=(Button)this.findViewById(R.id.calcTipButton);
billAmountTextView=(EditText)this.findViewById(R.id.billAmtEditText);
calcTipAmountButton.setOnClickListener(new onClickListener()
{
#Override
public void onClick(View v) {
calculateTip();
}
});
}
and in activity_fast_tip
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".FastTipActivity" >
<EditText
android:id="#+id/billAmtEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:ems="10"
android:gravity="right|center_vertical"
android:hint="#string/billAmount"
android:inputType="number|numberSigned|numberDecimal" >
<requestFocus />
</EditText>
<Button
android:id="#+id/calcTipButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/billAmtEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="#string/calculateTip" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/billAmtEditText"
android:layout_below="#id/calcTipButton"
android:layout_marginTop="18dp"
android:text="#string/tipPercentage"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/TextView01"
android:layout_below="#+id/TextView01"
android:layout_marginLeft="0dp"
android:layout_marginTop="18dp"
android:text="#string/tipAmount"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="18dp"
android:text="#string/totalAmount"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FF0000" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/billAmtEditText"
android:layout_marginBottom="35dp"
android:text="#string/button" />
use layout inflater
http://developer.android.com/reference/android/view/LayoutInflater.html
or Include
<include
android:layout_width="fill_parent"
android:layout_height="fill_parent"
layout="#layout/activity_setting"
/>
u can use include tag a layout like this into another layout
titlebar.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:background="#color/titlebar_bg">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/gafricalogo" />
</FrameLayout>
some other layout where we include that titlebar.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background="#color/app_bg"
android:gravity="center_horizontal">
<include layout="#layout/titlebar"/>
<TextView android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:text="#string/hello"
android:padding="10dp" />
...
</LinearLayout>
http://developer.android.com/training/improving-layouts/reusing-layouts.html
2. u can use LayoutInflater
code snippet
LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View someView = inflater.inflate(R.layout.ur_layout,null); //2nd parameter is for viewgroup
which_layout_u_want_to_add.addView(someView);
http://developer.android.com/reference/android/view/LayoutInflater.html

Android float button over scroll view

I have to put a button at a fix position(top-right) so that when I scroll the screen/view, the button is always visible. It's like a button floating over the view. The button is visible over the scroll view all the time.
I made a dummy app and it works
here is the layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout android:layout_width="match_parent" android:id="#+id/relativeLayout1" android:layout_height="wrap_content">
<ScrollView android:id="#+id/scrollView1" android:layout_height="fill_parent" android:layout_width="fill_parent">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<RatingBar android:id="#+id/ratingBar1" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content"></RatingBar>
<Spinner android:layout_width="wrap_content" android:id="#+id/spinner1" android:layout_weight="1" android:layout_height="wrap_content"></Spinner>
<Spinner android:layout_width="wrap_content" android:id="#+id/spinner2" android:layout_height="wrap_content" android:layout_weight="1"></Spinner>
<SeekBar android:id="#+id/seekBar1" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="match_parent"></SeekBar>
<QuickContactBadge android:layout_width="wrap_content" android:id="#+id/quickContactBadge1" android:layout_weight="1" android:layout_height="wrap_content"></QuickContactBadge>
<RatingBar android:id="#+id/ratingBar2" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content"></RatingBar>
<RadioGroup android:layout_width="wrap_content" android:id="#+id/radioGroup1" android:layout_weight="1" android:layout_height="wrap_content">
<RadioButton android:text="RadioButton" android:layout_width="wrap_content" android:id="#+id/radio0" android:layout_height="wrap_content" android:checked="true"></RadioButton>
<RadioButton android:text="RadioButton" android:layout_width="wrap_content" android:id="#+id/radio1" android:layout_height="wrap_content"></RadioButton>
<RadioButton android:text="RadioButton" android:layout_width="wrap_content" android:id="#+id/radio2" android:layout_height="wrap_content"></RadioButton>
</RadioGroup>
<Spinner android:layout_width="match_parent" android:id="#+id/spinner3" android:layout_height="wrap_content" android:layout_weight="1"></Spinner>
<TextView android:layout_width="wrap_content" android:id="#+id/textView1" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView" android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
<Button android:layout_width="wrap_content" android:text="Button" android:layout_height="wrap_content" android:layout_weight="1" android:id="#+id/button2"></Button>
<ProgressBar android:layout_width="wrap_content" android:layout_weight="1" android:id="#+id/progressBar1" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal"></ProgressBar>
<RatingBar android:id="#+id/ratingBar3" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content"></RatingBar>
<QuickContactBadge android:layout_width="wrap_content" android:id="#+id/quickContactBadge2" android:layout_weight="1" android:layout_height="wrap_content"></QuickContactBadge>
<Button android:layout_width="wrap_content" android:text="Button" android:layout_height="wrap_content" android:layout_weight="1" android:id="#+id/button3"></Button>
<CheckBox android:layout_width="wrap_content" android:text="CheckBox" android:id="#+id/checkBox1" android:layout_height="wrap_content" android:layout_weight="1"></CheckBox>
</LinearLayout>
</ScrollView>
<Button android:layout_height="wrap_content" android:text="Button" android:layout_width="wrap_content" android:id="#+id/button1"></Button>
</RelativeLayout>
</LinearLayout>
You should have a relative layout. Inside the layout you will have a scrollview to fill the parent both in height and with and the button will be also inside the layout but it will have align with parent top to true...
this is the answer, if you have any questions ask again
I guess you are using xml files to define your layout. Then you need to define the button outside the ScrollView definition, for example:
<ScrollView
...>
...
</ScrollView>
<Button
...>
</Button>
Guys I know this is a old post just FYI, Google has come up with a library to support the a lot of cool stuff like float button, etc. Worth a look.
Google Design Support Lib

How to prevent Soft Keyboard from resizing background image

I have a typical listview with an edittext and a button at the bottom of the activity.
When I click onto the edittext, the soft keyboard appears, I am able to scroll the items in the listview but it re-sizes my background image.
I have tried android:windowSoftInputMode="adjustResize" but no difference.
I have tried android:windowSoftInputMode="adjustPan". The image does not get squashed, the whole layout shifts upwards and I lose the title bar. I can only scroll the list if the list items exceed the layout size.
Basically, I want to maintain the title bar, retain the background image without re-sizing and allow scrolling of list items. Anyone managed to do this? Thanks!
for listview you need to use
android:isScrollContainer="false"
and add this to your activity in manifest.xml
android:windowSoftInputMode="adjustPan"
I have tried so may solutions for solving this problem. android:windowSoftInputMode="adjustPan" will make your whole screen shift with keyboard. Generally we have a title of the screen on the top. Using this flag it will also go out of the visible area, which make bad user experience. I use android:windowSoftInputMode="adjustResize" This will resize the whole screen but it will cause the same problem #Maurice state in the question.
So here is my final solution:
In Manifest
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
In XMl
Dont Set any background here.And keep your view under ScrollView
In Java
You need to set the background to window:
getWindow().setBackgroundDrawableResource(R.drawable.bg_wood) ;
Go to the Androidmanifest.xml and:
activity name="activityname" android:windowSoftInputMode="stateVisible|adjustPan"
There is no way to prevent the soft keyboard from resizing a background image.
Use this scaleType(matrix) and prepare a suitable image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/RelativeLayoutchat"
>
<LinearLayout
android:orientation="horizontal"
android:gravity ="clip_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true">
<ImageView
android:gravity ="clip_horizontal"
android:id="#+id/chat_bak_img"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="matrix">
</ImageView>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/chat"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:transcriptMode="alwaysScroll"
android:divider="#000000"
android:clickable="false"
android:layout_weight="9"
android:cacheColorHint="#00000000"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
style="#android:style/ButtonBar"
android:gravity="center"
android:paddingLeft="3dip"
android:paddingTop="3dip"
android:paddingRight="3dip">
<EditText
android:id="#+id/chatMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="5"
android:enabled="true"
android:textSize="17sp"
android:maxLength="150"/>
<Button
android:id="#+id/sendMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/send_withSpace"
android:layout_weight="4"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Use android:windowSoftInputMode="adjustResize" and simply wrap your background ImageView in a ScrollView.
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"
android:overScrollMode="never">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
I have the same problem with imageview resize while keyboard up i have solved with manifest android:windowSoftInputMode="adjustPan" and following is the layout example in my case
i.e frg_write_social:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frg_writeyourpost_ll_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:isScrollContainer="false"
android:scrollbars="none" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/frg_writeyourpost_rl_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/frg_writeyourpost_ll_bottum"
android:layout_alignParentTop="true"
android:minHeight="400dip" >
<ImageView
android:id="#+id/frg_writyourpost_iv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
</RelativeLayout>
<LinearLayout
android:id="#+id/frg_writeyourpost_ll_bottum"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#android:color/white"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center"
android:text="Write your post"
android:textColor="#727F8D"
android:textSize="10sp" />
<com.example.views.CustomEditText
android:id="#+id/frg_writeyourpost_et_message"
android:layout_width="match_parent"
android:layout_height="#dimen/slide_image"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#null"
android:inputType="textMultiLine"
android:maxHeight="#dimen/slide_image"
android:maxLines="3"
android:textSize="11sp" >
</com.example.views.CustomEditText>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/frg_writeyourpost_tv_totalcharacter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0"
android:textColor="#727F8D"
android:textSize="8sp" />
<TextView
android:id="#+id/frg_writeyourpost_tv_characterLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="center"
android:text="character"
android:textColor="#727F8D"
android:textSize="8sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<RadioGroup
android:id="#+id/frg_writepost_fbtw_rggroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/frg_writepost_rb_facebook"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/fb_check_selector"
android:button="#android:color/transparent"
android:gravity="center"
android:padding="10dip"
android:text="#string/post_for_facebook"/>
<View
android:layout_width="5dip"
android:layout_height="match_parent"
android:background="#android:color/transparent"/>
<RadioButton
android:id="#+id/frg_writepost_rb_twitter"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/tw_check_selector"
android:button="#android:color/transparent"
android:gravity="center"
android:padding="10dip"
android:text="#string/post_for_twitter"/>
</RadioGroup>
</LinearLayout>
</LinearLayout>
</LinearLayout>
if there is possible to load image dynamically you can resize image with picaaso while load in imageview
Use ImageView with fill_parent and centerCrop attributes in RelativeLayout. Like this;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/yazisma_arka_plan"
android:scaleType="centerCrop"
/>
<ListView
android:id="#+id/messages_view"
android:layout_width="fill_parent"...
I read a lot of answers over StackOverflow and took some from many to make my app works:
No ScrollView at all in my activity_main.xml
In AndroidManifest.xml added this attribute to the
<activity android:name=".MainActivity" ...>
tag:
android:windowSoftInputMode="adjustResize"
In MainActivity.java inside onCreate()
I added getWindow().setBackgroundDrawableResource(R.drawable.app_bg);
It works for me when all the other solutions I've tried didn't.
If you got up to here, I hope it'll work for you too.
Er, let me see ... pictures first!
The layout file act_login.xml.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/login_bkgd"
android:orientation="vertical"
android:paddingLeft="25dp"
android:paddingRight="25dp"
>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#0fff"
android:scrollbars="none"
android:listSelector="#0fff"
android:divider="#0fff"
android:dividerHeight="0dp"
android:isScrollContainer="true"
/>
<!--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->
<!--android:isScrollContainer="true"-->
<!--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->
<LinearLayout
android:id="#+id/loginItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
>
<ImageView
android:id="#+id/loginLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="35dp"
android:layout_marginTop="35dp"
android:scaleType="fitCenter"
android:src="#drawable/logo"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="35dp"
>
<View
android:layout_width="0dp"
android:layout_height="1px"
android:layout_weight="1"
android:background="#Ffff"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:text="WELCOME"
android:textColor="#Ffff"
android:textSize="14sp"
/>
<View
android:layout_width="0dp"
android:layout_height="1px"
android:layout_weight="1"
android:background="#Ffff"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/login_et_long"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
>
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:background="#null"
android:text="账号:"
android:textColor="#Ffff"
android:textSize="16sp"
/>
<EditText
android:id="#+id/loginUsername"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:hint="请输入手机号"
android:imeOptions="actionNext"
android:inputType="text"
android:singleLine="true"
android:textColor="#F000"
android:textSize="16sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="45dp"
android:layout_marginTop="10dp"
android:background="#drawable/login_et_long"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
>
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:background="#null"
android:text="密码:"
android:textColor="#Ffff"
android:textSize="16sp"
/>
<EditText
android:id="#+id/loginPassword"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:hint="请输入密码"
android:imeOptions="actionGo"
android:inputType="textPassword"
android:singleLine="true"
android:textColor="#F000"
android:textSize="16sp"
/>
</LinearLayout>
<TextView
android:id="#+id/login"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/login_button"
android:gravity="center"
android:padding="10dp"
android:text="#string/str_login"
android:textColor="#Ffff"
android:textSize="19sp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
The related Java codes.
EditText etUsername, etPassword;
EditText etFocus;
ViewGroup base;
int mSelection;
#Override
protected void onCreate(Bundle savedInstanceState) {
base=(ViewGroup)getLayoutInflater().inflate(R.layout.act_login, null);
setContentView(base);
getWindow().setBackgroundDrawable(base.getBackground());
base.setBackground(null);
super.onCreate(savedInstanceState);
}
#Override
protected void initViews() {
etUsername=(EditText)findViewById(R.id.loginUsername);
etPassword=(EditText)findViewById(R.id.loginPassword);
final ViewGroup item=(ViewGroup)findViewById(R.id.loginItem);
base.removeView(item);
final View[] items=new View[item.getChildCount()];
for(int i=0; i<item.getChildCount(); i++) items[i]=item.getChildAt(i);
item.removeAllViews();
ListView lv=(ListView)base.getChildAt(0);
lv.setAdapter(new BaseAdapter() {
public View getView(int i, View v, ViewGroup vg) {
if(etFocus!=null && getCurrentFocus()!=etFocus){
etFocus.requestFocus();
etFocus.setSelection(mSelection);
//etFocus=null;
}
return items[i];
}
public int getCount() {return items.length;}
public Object getItem(int position) {return null;}
public long getItemId(int position) {return 0;}
});
/*View.OnTouchListener listener=new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent e) {
if(e.getAction()!=MotionEvent.ACTION_UP) return false;
etFocus=(EditText)v;
mSelection=etFocus.getSelectionEnd();
ZZ.z("_________________ mSelection="+mSelection);
return false;
}
};
etUsername.setOnTouchListener(listener);
etPassword.setOnTouchListener(listener);*/
View.OnFocusChangeListener listener1=new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
etFocus=(EditText)v;
mSelection=etFocus.getSelectionStart();
ZZ.z("_________________ mSelection="+mSelection);
}
}
};
etUsername.setOnFocusChangeListener(listener1);
etPassword.setOnFocusChangeListener(listener1);
}
The AndroidManifest part.
<activity
android:name=".ui.activity.ActLogin"
android:label="#string/str_login"
android:theme="#style/myTheme"
/>
<!--android:windowSoftInputMode="adjustResize"-->
The style part.
<style name="myTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
This code doesn't work for me:
android:windowSoftInputMode="adjustResize"
But this does work:
android:windowSoftInputMode="adjustPan"
For those who aren't get it:
double ckeck if your xml already has a #drawable setted (this was the error for me, i was setting via android manifest but it was already setted on the root of xml)
after that create a theme style with background:
<style name="AppThemeWBackgroundG" parent="AppTheme">
<item name="android:windowBackground">#drawable/background_com_gradiente</item>
</style>
Then in your activity on AndroidManifest.xml:
<activity
android:name=".TelaLoginFuncionario"
android:windowSoftInputMode="adjustResize|stateAlwaysVisible"
android:theme="#style/AppThemeWBackgroundG"
android:fitsSystemWindows="true"
/>
and that's it: the activity enter in a screen with the keyboard up, resizing up the items and the background stays at normal size
all you need to do is to set the background gravity to the top
<item android:drawable="#drawable/background_image" android:gravity="top"/>
Here is tutorial

Resources