How to set Focus on top Item? - android-layout

I have one scroll view and but while I am running the code I found that some items in top are hides.
I want to show this scroll view from top most. please help me.
code is here
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:scrollX="0px">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/img_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/logo"
android:focusable="true"
android:layout_marginTop="1dip" />
<ImageView
android:id="#+id/img_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/jvdbanner" />
<ListView
android:id="#+id/main_list"
android:layout_width="fill_parent"
android:layout_height="279dip"
android:background="#84CFE7"
android:cacheColorHint="#00000000"
android:divider="#000000"
android:dividerHeight="1dip"
android:focusable="false"
android:fadingEdge="none"
android:scrollbars="none" />
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginTop="5dip"
android:background="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dip"
android:text="Copyright # 2012- JVD Properties, Inc."
android:textColor="#ffffff"
android:textSize="13sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dip"
android:text="All Rights Reserved."
android:textColor="#ffffff"
android:textSize="13sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>

Just Try this code..hope it works for you
final ScrollView main = (ScrollView) findViewById(R.id.scrollView1);
main.post(new Runnable() {
public void run() {
main.scrollTo(0,0);
}
});

Related

Android Portrait to Landcape Slider & ImageView not responsive

My Portrait View is looks Fine
My Landscape View alignment is collapsed
this is my code of activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/img_slideshow_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="#+id/img_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/indicator"
android:background="#color/PrimaryColor"
android:gravity="center"
android:ellipsize="end"
android:paddingBottom="2dp"
android:paddingLeft="5dp"
android:paddingRight="2dp"
android:paddingTop="2dp"
android:singleLine="true"
android:textColor="#ededed" />
</RelativeLayout>
<View android:id="#+id/div_a"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_below="#+id/img_slideshow_layout"
android:background="#color/view_divider_color" />
<View android:id="#+id/div_b"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_below="#+id/div_a"
android:background="#color/view_divider_color_2" />
<com.studiobluelime.utils.CirclePageIndicator
android:id="#+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/view_pager"
android:layout_marginBottom="4dp" />
</RelativeLayout>
<!--<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
style="#style/Base.Widget.AppCompat.ProgressBar"
android:id="#+id/progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true" />
<android.support.v7.widget.RecyclerView
android:id="#+id/card_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>-->
<!-- <android.support.v7.widget.RecyclerView
android:id="#+id/card_recycler_view_new"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"/>-->
</LinearLayout>
</ScrollView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="100dp"
app:srcCompat="#drawable/shop_online"
android:layout_marginLeft="140dp"
android:id="#+id/shop_online"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:layout_marginTop="200dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/nandme"
android:adjustViewBounds="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="320dp"
android:scaleType="fitXY"
android:id="#+id/nandme"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="#drawable/storelocation"
android:adjustViewBounds="true"
android:layout_marginLeft="258dp"
android:id="#+id/storelocation"
android:scaleType="fitXY"
android:layout_marginTop="250dp"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="#drawable/promotins"
android:adjustViewBounds="true"
android:layout_marginLeft="20dp"
android:id="#+id/promotins"
android:scaleType="fitXY"
android:layout_marginTop="240dp"/>
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="fill_parent"
android:layout_height="157dp" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:itemIconTint="#color/PrimaryDarkColor"
app:itemTextColor="#color/colorAccent"
app:itemBackground="#drawable/ripple"
app:menu="#menu/navigation_items" />
</android.support.v4.widget.DrawerLayout>
I wrote this code in four layouts: layout/activity_main.xml,layout-small/ activity_main.xml, layout-large/activity_main.xml, layout-xlarge/activity_main.xml but it did not change. I have attached a screen shot here. Please click the above name "My Portrait View is looks Fine My Landscape View alignment is collapsed"

How to add more content in layout? is it possible to define more than 1 textview inside scrollView?

This my code in this I have been using scrollView and inside it two textViews to add more content but it is working only when there is one textView please what changes i do to add more content?And here I want space between those textViews(content) but in my code i am trying for that but the content is overlapped and there is no proper space between contents.please help me..!
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.example.hp.kludge.AndroidActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:weightSum="1">
<TextView
android:id="#+id/tvA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="ANDROID"
android:textColor="#f6080101"
android:textColorHighlight="#df1425"
android:textSize="35dp"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:background="#e62027"
android:layout_height="2dp"
android:layout_below="#+id/tvC" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:fillViewport="true"
android:orientation="vertical">
<TextView
android:id="#+id/tvWhat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tvC"
android:layout_marginTop="44dp"
android:text="What is Android?"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="22dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Content"
android:id="#+id/tvt" />
</ScrollView>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/butNext"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#abc3fb" />
</RelativeLayout>

GridView does not fill screen

I have a "grid_test.xml"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayoutGrid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<GridView
android:id="#+id/gridView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp" >
</GridView>
</LinearLayout>
I am including this in another layout with header and footer:
<?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/commonlayout" >
<LinearLayout android:id="#+id/llheader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#android:color/white">
<RelativeLayout android:id="#+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_gravity="center">
<Button
android:id="#+id/Button_Logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="2dp"
android:layout_centerVertical="true"
android:background="#drawable/ic_launcher"/>
<Button
android:id="#+id/Button_settings"
android:layout_marginLeft="2dp"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/ic_launcher"/>
</RelativeLayout>
</LinearLayout>
<ScrollView android:id="#+id/svdata"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:layout_below="#+id/llheader"
android:layout_above="#+id/llfooter" >
<LinearLayout
android:id="#+id/lldata"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/backgound_color"
android:orientation="vertical"
android:padding="5dp" >
<include layout="#layout/grid_test" />
</LinearLayout>
</ScrollView>
<LinearLayout android:id="#+id/llfooter"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_margin="0dp"
android:layout_alignParentBottom="true"
>
<RadioGroup
android:id="#+id/radiogroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/btnOption1"
style="#style/navbar_button"
android:drawableTop="#drawable/ic_launcher"
android:singleLine="true"/>
<RadioButton
android:id="#+id/btnOption2"
style="#style/navbar_button"
android:drawableTop="#drawable/ic_launcher"
android:singleLine="true"/>
<RadioButton
android:id="#+id/btnOption3"
style="#style/navbar_button"
android:drawableTop="#drawable/ic_launcher"/>
</RadioGroup>
</LinearLayout>
</RelativeLayout>
My problem is that the included GridView layout does not fill the screen between header and footer.
What could be causing the problem?
Ok. I found it. Removing the ScrollView, makes it work as expected.
<?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/commonlayout" >
<LinearLayout android:id="#+id/llheader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#android:color/white">
<RelativeLayout android:id="#+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_gravity="center">
<Button
android:id="#+id/Button_Logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="2dp"
android:layout_centerVertical="true"
android:background="#drawable/ic_launcher"/>
<Button
android:id="#+id/Button_settings"
android:layout_marginLeft="2dp"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/ic_launcher"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/lldata"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/backgound_color"
android:orientation="vertical"
android:layout_below="#+id/llheader"
android:layout_above="#+id/llfooter"
android:padding="5dp" >
<include layout="#layout/grid_test" />
</LinearLayout>
<LinearLayout android:id="#+id/llfooter"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_margin="0dp"
android:layout_alignParentBottom="true"
>
<RadioGroup
android:id="#+id/radiogroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/btnOption1"
style="#style/navbar_button"
android:drawableTop="#drawable/ic_launcher"
android:singleLine="true"/>
<RadioButton
android:id="#+id/btnOption2"
style="#style/navbar_button"
android:drawableTop="#drawable/ic_launcher"
android:singleLine="true"/>
<RadioButton
android:id="#+id/btnOption3"
style="#style/navbar_button"
android:drawableTop="#drawable/ic_launcher"/>
</RadioGroup>
</LinearLayout>
</RelativeLayout>

Admob Layout for Android

I have the following code....and I can't seem to get the ads to run outside my scroll view. I have tried to follow other questions on this topic. please assist. All of my adds are showing on top of my content. I would prefer the ads run outside my scroll view.
my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxxxxxxxxx"
ads:loadAdOnCreate="true" />
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layoutbottom"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:padding="5dp" >
<!-- android:layout_height="456dp" -->
<TextView
android:id="#+id/txtPlaceName"
style="#style/HeaderText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/txtAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/txtStory"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/txtURL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Try adding android:layout_alignParentTop="true" on your AdView and android:layout_below="#id/adView" on your ScrollView.

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