I've a relative layout in android for a chat application.The problem is that the listview on my screen when grows the last elements are hidden behind the textbox and button which I've placed at the bottom.
I am using the following layout file.
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="#+id/PreviousChatsButton"
android:padding="5dip"
android:text="#string/ViewPreviousChats"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:focusable="true"
>
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<TextView android:id="#+id/NoChatsMsg"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/NoNewChatMsg"
/>
<Button
android:id="#+id/SubmitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/Submit"
android:onClick="SubmitButtonClick" />
<EditText
android:id="#+id/Chatbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/SubmitButton"
android:layout_alignBottom="#id/SubmitButton"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/SubmitButton"
android:ems="10"
android:inputType="text" >
</EditText>
</RelativeLayout>
what you want to do is in the LinearLayout do android:layout_above="#+id/Chatbox" that will make sure it does not go below it
//try this its working fine for me
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/PreviousChatsButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:gravity="center_horizontal"
android:padding="5dip"
android:text="ViewPreviousChats" >
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/NoChatsMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/NoNewChatMsg" />
<Button
android:id="#+id/SubmitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="SubmitButtonClick"
android:text="#string/Submit" />
<EditText
android:id="#+id/Chatbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/SubmitButton"
android:layout_alignBottom="#id/SubmitButton"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/SubmitButton"
android:ems="10"
android:inputType="text" >
</EditText>
</LinearLayout>
</LinearLayout>
Use android:layout_above to avoid this problem :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/SubmitButton" ... />
<LinearLayout
android:layout_above="#id/SubmitButton" ... >
...
</LinearLayout>
Note that you have to declare your button before the LinearLayout for this to work.
Related
I have a ListView that is not scrolling for complete. I inserted 20 items, but the listview is scrolling until the item 15º.
My Layout XML code here :
<?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:orientation="vertical"
android:weightSum="1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="#color/sky" >
<TextView
android:id="#+id/tvQuote"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:gravity="center_vertical|center_horizontal"
android:scrollbars="none"
android:text="#string/QuoteTeste"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textSize="14pt" />
<Space
android:id="#+id/espaco"
android:layout_width="wrap_content"
android:layout_height="30dp" >
</Space>
<TextView
android:id="#+id/tvAutor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvQuote"
android:layout_below="#+id/tvQuote"
android:layout_marginTop="22dp"
android:text="(Carlos Drummond)"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/white" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/checklistview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>
</LinearLayout>
Here a screenshot:
I don't understand WHY this is happening. For example, If I put 6 items, the 6º item is not show and I can't scroll the listview. Missing something?
The problem is in your layout xml
change it with this one:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/topPart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/sky" >
<TextView
android:id="#+id/tvQuote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:gravity="center_vertical|center_horizontal"
android:scrollbars="none"
android:text="#string/QuoteTeste"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textSize="14pt" />
<Space
android:id="#+id/espaco"
android:layout_width="wrap_content"
android:layout_height="30dp" >
</Space>
<TextView
android:id="#+id/tvAutor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvQuote"
android:layout_below="#+id/tvQuote"
android:layout_marginTop="22dp"
android:text="(Carlos Drummond)"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/white" />
</RelativeLayout>
<ListView
android:id="#+id/checklistview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/topPart" >
</ListView>
</RelativeLayout>
You should not add multiple enties below each other using android:layout_height="fill_parent" or "match_parent" (which is the same) in the same layout as you do in the LinearLayout.
Make it another RelativeLayout with using layout_below, layout_parentOnBottom and other options or place everything into one huge relative layout.
<?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:orientation="vertical"
android:weightSum="1" >
<RelativeLayout
android:id="#+id/toppart"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/sky" >
<TextView
android:id="#+id/tvQuote"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:gravity="center_vertical|center_horizontal"
android:scrollbars="none"
android:text="#string/QuoteTeste"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textSize="14pt" />
<Space
android:id="#+id/espaco"
android:layout_width="wrap_content"
android:layout_height="30dp" >
</Space>
<TextView
android:id="#+id/tvAutor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvQuote"
android:layout_below="#+id/tvQuote"
android:layout_marginTop="22dp"
android:text="(Carlos Drummond)"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/white" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/bottompart"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_below="#+id/toppart"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#+id/checklistview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>
I've tried everything, and looked up everywhere..!
I'm trying to put a listview within a scrollview, and a button at the bottom of the screen fixed..
This is my code:
<?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:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/rlCommento" />
<RelativeLayout
android:id="#+id/rlCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<EditText
android:id="#+id/etCCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="15"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bCInviaCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/etCCommento"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_weight="85"
android:text="Commenta!" />
</RelativeLayout>
</RelativeLayout>
It seems working in the project, but when I try it on the emulator, it doesn't work!
Any advice ? Thanks!
This is what you have to do:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="Button" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
android:layout_centerHorizontal="true" >
</ListView>
</RelativeLayout>
You can use LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<RelativeLayout
android:id="#+id/rlCommento"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
...
</RelativeLayout>
</LinearLayout>
First: Don't put list view inside scroll view
Second: make your top most parent width n height to match parent
Third: add a new layout at bottom and add button inside this layout, something like this, give layout some weight
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingBottom="7dp"
android:paddingTop="7dp" >
<Button
android:id="#+id/score_board"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_weight="1"
android:text="OK" />
</LinearLayout>
// Try this way,hope this will help you to solve your problem...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp">
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:id="#+id/rlCommento"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<EditText
android:id="#+id/etCCommento"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bCInviaCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Commenta!" />
</LinearLayout>
</LinearLayout>
To do that you have to LinearLayout vertical instead of RelativeLayout and set ListView weight=1 and layout_height=0dp.
This should work just as needed:
<?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" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RelativeLayout
android:id="#+id/rlCommento"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/etCCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="15"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bCInviaCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/etCCommento"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_weight="85"
android:text="Commenta!" />
</RelativeLayout>
Hope I understood your problem correctly. No need of keeping ListView inside scrollview. Just try following snippet. It will may for you.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/bCInviaCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Commenta!"
android:layout_below="#id/list" />
</RelativeLayout?
I am developing an Android Application and I have an Activity that looks like this. I have a header and a footer that have fixed positions, and a ListView with clickable items in the middle. Below the ListView, I have a button.
It is working when I have a few items, but as I add more items, the button begins to disappear, like this.
When I have more items in that list that can be shown in the page, I have a scroll in the list. If I scroll down like this I can see all the items in the list, but the button is hidden.
I have had a lot of problems before trying to add a ListView inside a ScrollView, so I know it doesn't work. As I am new in Android development, perhaps my XML layout files are a bit confusing, but I have a parent LinearLayout with two RelativeLayouts inside, one for the header and one for the middle and footer. The XML is something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFF">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/background"
android:gravity="center_vertical">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="#string/baseTitle"
android:textColor="#FFFFFF"
android:layout_centerVertical="true"
android:textSize="18dp"
android:textStyle="bold"/>
<Button
android:id="#+id/buttonHelp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#drawable/button_help"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="fill_vertical">
<LinearLayout
android:id="#+id/buttonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="#bdbdbd"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/bottomButtomBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:id="#+id/myGroups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/myGroups"
android:gravity="center"
android:textSize="13dp"
android:textColor="#000000"
android:background="#layout/button_meus_grupos"/>
<Button
android:id="#+id/createGroups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:text="#string/createGroups"
android:gravity="center"
android:textSize="13dp"
android:textColor="#000000"
android:background="#layout/button_criar_grupos"/>
<Button
android:id="#+id/configurations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="#string/configurations"
android:gravity="center"
android:textSize="13dp"
android:textColor="#000000"
android:background="#layout/button_configuracoes"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_above="#id/buttonBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/listContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical"
>
<RelativeLayout
android:id="#+id/searchBarLayout"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:background="#ffffff"
android:gravity="center_vertical"
android:clickable="true"
>
<TextView
android:id="#+id/myGroupsLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/myGroups"
android:layout_centerInParent="true"
android:textColor="#bdbdbd"
android:textSize="16dp"
android:textStyle="bold"
/>
<ImageView
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_search" />
</RelativeLayout>
<View android:layout_height="2dip"
android:layout_width="wrap_content"
android:background="#cccccc"
/>
<ListView android:id="#+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:cacheColorHint="#000000"
/>
<Button
android:id="#+id/buttonCreateGroup"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="#layout/button_confirm"
android:layout_gravity="center_horizontal"
android:text="#string/createOneGroup"
android:textColor="#FFFFFF"
android:textSize="22dp"
android:layout_marginTop="15dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Does anyone have any tips on how can I keep the footer fixed, scroll down until the end of the list and then show the button? I want that it looks like the button is the last item at the List.
EDIT: Entire XML posted
The ListView and the Button should be in a RelativeLayout and in the Button you should set android:layout_below="#id/listview"
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#000000"
android:textColor="#000000" />
<Button
android:layout_below="#id/listview"
android:id="#+id/buttonCreateGroup"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginTop="15dp"
android:background="#layout/button_confirm"
android:text="#string/createOneGroup"
android:textColor="#FFFFFF"
android:textSize="22dp" />
</RelativeLayout>
Try it in the following manner:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout //Header
android:layout_alignParentTop="true">
</RelativeLayout>
<ListView
android:layout_below="#+id/header" />
<RelativeLayout //Button(footer)
android:layout_alignParentBottom="true"
android:layout_below="#+id/listView" >
</RelativeLayout>
</RelativeLayout>
The only way I could achieve the exact requirements I explained above was doing the following:
-In the XML file with the layout of the list items, I added a button with android:visibility="gone".
-In my custom ListView adapter, I always add an empty object in the last position. I simply add an object with a flag that shows it is the last in the list.
-In the method getView() that I override in the custom Adapter, I check if the object in the current position has the flag indicating that it is the last in the list. If so, I set the button visibility to VISIBLE, otherwise I fill the other components.
If anyone is facing the same problem and needs some sample code from my solution just ask here.
Try this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="baseTitle"
android:textColor="#FFFFFF"
android:textSize="18dp"
android:textStyle="bold" />
<Button
android:id="#+id/buttonHelp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/buttonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/bottomButtomBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<Button
android:id="#+id/myGroups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:gravity="center"
android:text="myGroups"
android:textColor="#000000"
android:textSize="13dp" />
<Button
android:id="#+id/createGroups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:gravity="center"
android:text="createGroups"
android:textColor="#000000"
android:textSize="13dp" />
<Button
android:id="#+id/configurations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:gravity="center"
android:text="configurations"
android:textColor="#000000"
android:textSize="13dp" >
</Button>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/buttonBar"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/listContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/searchBarLayout"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/myGroupsLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="myGroups"
android:textColor="#bdbdbd"
android:textSize="16dp"
android:textStyle="bold" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp" >
</ImageView>
</RelativeLayout>
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="280dip"
android:layout_margin="7dip"
android:scrollbars="none" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#000000"
android:textColor="#000000" />
<Button
android:id="#+id/buttonCreateGroup"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginTop="15dp"
android:text="createOneGroup"
android:textColor="#FFFFFF"
android:textSize="22dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
I'm doing an android app and I want to separate layout in 3 parts like this:
but now the button is over the second listview but on the bottom of the screen, I don't know why.
I don't know if I have to use relativeLayout or linearLayout to including the listviews, and text are inside this or outside of relativelayout/linearLayout, and the last button what?
this is my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="#+id/imageSelected"
android:text="#string/imgSelected"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginBottom="3dip"/>
<LinearLayout
android:id="#+id/linearLayoutImagenes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_below="#+id/imageSelected" >
<ListView
android:id="#+id/listaFusionPhotos"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout >
<TextView android:id="#+id/nameSelected"
android:text="#string/namSelected"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="#+id/linearLayoutImagenes"
android:layout_marginBottom="3dip"/>
<LinearLayout
android:id="#+id/linearLayoutNombres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_below="#+id/nameSelected"
>
<ListView
android:id="#+id/listaFusionNombres"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout >
<Button
android:id="#+id/fusion"
android:layout_width="160dip"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayoutNombres"
android:layout_marginTop="3dip"
android:text="Fusionar"
android:onClick="Mostrar_Registrados"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
Try this. this looks like exactly same of the picture.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="11" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_weight="1"/>
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="4">
</ListView>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ListView
android:id="#+id/listView2"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="4">
</ListView>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutNombres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_below="#+id/nameSelected"
android:layout_above="#+id/fusion" // "line added"
>
<Button
android:id="#+id/fusion"
android:layout_width="160dip"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayoutNombres" --> "remove this line"
android:layout_marginTop="3dip"
android:text="Fusionar"
android:onClick="Mostrar_Registrados"
android:layout_alignParentBottom="true"/>
I have an EditText (that the user can type numbers in),
so when the user clicks on the EditText text box a keyboard with numbers is opened.
as you can see the keyboard hides a small part of the text box.
But when I press a key, for example, 0, it looks ok.
Is there anything I can do (besides putting the EditText higher) so it will looks like it does in the second picture?
Edit: the .xml code:
<?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" android:weightSum="1">
<RelativeLayout android:id="#+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content" android:orientation="vertical" android:layout_height="wrap_content" android:id="#+id/linearLayout1" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignParentRight="true">
<android.widget.CheckedTextView android:id="#+id/checkedTextView1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp" android:text="#string/toString"></android.widget.CheckedTextView>
<AutoCompleteTextView android:layout_height="wrap_content" android:id="#+id/autoCompleteTextView1" android:layout_width="fill_parent" android:text="#string/emptyString" android:textSize="17sp" android:gravity="top|left" android:minHeight="62dp">
<requestFocus></requestFocus>
</AutoCompleteTextView>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/linearLayout2">
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.33333333333" android:text="#string/contactsString" android:textSize="17sp" android:id="#+id/contactsButton"></Button>
<Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="#string/groupsString" android:layout_width="fill_parent" android:id="#+id/groupsButton" android:textSize="17sp"></Button>
<Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="#string/favouritesString" android:layout_width="fill_parent" android:id="#+id/button3" android:textSize="17sp"></Button>
</LinearLayout>
<TextView android:id="#+id/textView1" android:text="#string/messageString" android:layout_height="wrap_content" android:textSize="17sp" android:layout_width="fill_parent"></TextView>
<EditText android:layout_height="wrap_content" android:id="#+id/editText1" android:layout_width="fill_parent" android:gravity="top|left" android:minHeight="105dp"></EditText>
<TextView android:id="#+id/textView2" android:text="#string/repetition" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp"></TextView>
<Spinner android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/spinner"></Spinner>
<LinearLayout android:layout_height="wrap_content" android:id="#+id/linearLayout3" android:layout_width="fill_parent">
<ImageView android:src="#drawable/button_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/imageView1" android:layout_weight="0.1"></ImageView>
<EditText android:layout_height="wrap_content" android:id="#+id/timeET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4"></EditText>
<ImageView android:src="#drawable/button_date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/imageView2" android:layout_weight="0.1"></ImageView>
<EditText android:layout_height="wrap_content" android:id="#+id/dateET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4" android:layout_marginRight="3dp"></EditText>
</LinearLayout>
<RelativeLayout android:id="#+id/relativeLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/linearLayout4" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentLeft="true">
<Button android:layout_weight="0.5" android:layout_height="wrap_content" android:text="#string/button_ok" android:layout_width="fill_parent" android:id="#+id/button4" android:textSize="17sp"></Button>
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="#+id/button5" android:layout_weight="0.5" android:text="#string/button_cancel" android:textSize="17sp"></Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
I have tried your XML and yes you are right the problem occur.
To solve the problem I have written this line in my MainActivity.java hope this help to you,And put the layout XML in ScrollView.
Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.temp);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
final EditText time = (EditText)findViewById(R.id.timeET);
time.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
time.requestLayout();
MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
return false;
}
});
final EditText date = (EditText)findViewById(R.id.dateET);
date.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
time.requestLayout();
MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
return false;
}
});
}
And The XML is Like,
<?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" >
<ScrollView android:id="#+id/scrollView1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:weightSum="1">
---
---
---
</ScrollView>
</LinearLayout>
Change to ScrollView in this way:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true" >
<android.widget.CheckedTextView
android:id="#+id/checkedTextView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="17sp"
android:text="#string/toString" />
<AutoCompleteTextView
android:layout_height="wrap_content"
android:id="#+id/autoCompleteTextView1"
android:layout_width="fill_parent"
android:text="#string/emptyString"
android:textSize="17sp"
android:gravity="top|left"
android:minHeight="62dp" >
<requestFocus></requestFocus>
</AutoCompleteTextView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2" >
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="0.33333333333"
android:text="#string/contactsString"
android:textSize="17sp"
android:id="#+id/contactsButton" />
<Button
android:layout_weight="0.33333333333"
android:layout_height="wrap_content"
android:text="#string/groupsString"
android:layout_width="fill_parent"
android:id="#+id/groupsButton"
android:textSize="17sp" />
<Button
android:layout_weight="0.33333333333"
android:layout_height="wrap_content"
android:text="#string/favouritesString"
android:layout_width="fill_parent"
android:id="#+id/button3"
android:textSize="17sp" />
</LinearLayout>
<TextView
android:id="#+id/textView1"
android:text="#string/messageString"
android:layout_height="wrap_content"
android:textSize="17sp"
android:layout_width="fill_parent" />
<EditText
android:layout_height="wrap_content"
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:gravity="top|left"
android:minHeight="105dp" />
<TextView
android:id="#+id/textView2"
android:text="#string/repetition"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="17sp" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner" />
<LinearLayout
android:layout_height="wrap_content"
android:id="#+id/linearLayout3"
android:layout_width="fill_parent" >
<ImageView
android:src="#drawable/button_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView1"
android:layout_weight="0.1" />
<EditText
android:layout_height="wrap_content"
android:id="#+id/timeET"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_weight="0.4" />
<ImageView
android:src="#drawable/button_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:layout_weight="0.1" />
<EditText
android:layout_height="wrap_content"
android:id="#+id/dateET"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_weight="0.4"
android:layout_marginRight="3dp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/linearLayout4"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true" >
<Button
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:text="#string/button_ok"
android:layout_width="fill_parent"
android:id="#+id/button4"
android:textSize="17sp" />
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/button5"
android:layout_weight="0.5"
android:text="#string/button_cancel"
android:textSize="17sp" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
put the entire view inside a ScrollView and set the android:windowSoftInputMode = adjustPan it will do the trick.
you just need to add this piece of code,
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
Your linear layout here....
</ScrollView>
I have tested it on my HTC Desire and its working fine for me hope it will work for you too.
Set android:windowSoftInputMode on the Activity to "adjustPan":
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing.
Beware of one potential bug when using this technique with a fullscreen activity.
You can give some hints to the system on how to handle this via android:windowSoftInputMode element on the declared activity in the AndroidManifest. Try the "adjustResize" value.
android:windowSoftInputMode
This is a much simpler fix than the accepted answer. The key is the <item name="android:windowSoftInputMode">adjustUnspecified</item> line. Add it to your styles.xml:
<style name="AppTheme" parent="#android:Theme.Holo.Light.DarkActionBar">
<item name="android:alertDialogTheme">#style/iconPopUpDialogTheme</item>
</style>
<style name="DialogAppTheme" parent="AppTheme">
<item name="android:dialogTheme">#style/iconPopUpDialogTheme</item>
</style>
<style name="PopUpDialogTheme">
<item name="android:windowSoftInputMode">adjustUnspecified</item>
</style>
try changing linear layout to scroll view...so that if keyboard comes above editt text user can scroll and type...
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="1">
<RelativeLayout android:id="#+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content"
android:orientation="vertical" android:layout_height="wrap_content"
android:id="#+id/linearLayout1" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
android:layout_alignParentRight="true">
<android.widget.CheckedTextView
android:id="#+id/checkedTextView1" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:textSize="17sp"></android.widget.CheckedTextView>
<AutoCompleteTextView android:layout_height="wrap_content"
android:id="#+id/autoCompleteTextView1" android:layout_width="fill_parent"
android:textSize="17sp" android:gravity="top|left"
android:minHeight="62dp">
<requestFocus></requestFocus>
</AutoCompleteTextView>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/linearLayout2">
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:layout_weight="0.33333333333"
android:textSize="17sp" android:id="#+id/contactsButton"></Button>
<Button android:layout_weight="0.33333333333"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:id="#+id/groupsButton" android:textSize="17sp"></Button>
<Button android:layout_weight="0.33333333333"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:id="#+id/button3" android:textSize="17sp"></Button>
</LinearLayout>
<TextView android:id="#+id/textView1" android:layout_height="wrap_content"
android:textSize="17sp" android:layout_width="fill_parent"></TextView>
<EditText android:layout_height="wrap_content" android:id="#+id/editText1"
android:layout_width="fill_parent" android:gravity="top|left"
android:minHeight="105dp"></EditText>
<TextView android:id="#+id/textView2" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:textSize="17sp"></TextView>
<Spinner android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/spinner"></Spinner>
<LinearLayout android:layout_height="wrap_content"
android:id="#+id/linearLayout3" android:layout_width="fill_parent">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/imageView1"
android:layout_weight="0.1"></ImageView>
<EditText android:layout_height="wrap_content" android:id="#+id/timeET"
android:inputType="number" android:layout_width="wrap_content"
android:layout_weight="0.4"></EditText>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/imageView2"
android:layout_weight="0.1"></ImageView>
<EditText android:layout_height="wrap_content" android:id="#+id/dateET"
android:inputType="number" android:layout_width="wrap_content"
android:layout_weight="0.4" android:layout_marginRight="3dp"></EditText>
</LinearLayout>
<RelativeLayout android:id="#+id/relativeLayout2"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/linearLayout4"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true">
<Button android:layout_weight="0.5" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="#+id/button4"
android:textSize="17sp"></Button>
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="#+id/button5"
android:layout_weight="0.5" android:textSize="17sp"></Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
please make necesscery changes...i have removed strings and drawable src for my convience..u need to change first
linear layout to scrollview..try without this
android:windowSoftInputMode = adjustPan
Add this simple line in your Manifest.xml file:
android:windowSoftInputMode="adjustResize|stateHidden"