Trouble getting relative layout right - android

I have been pulling my hair out trying to get my relative layout setup the way I want. I want to have a EditText on the left with a TextView in the middle and a Button to the right and all those over a ListView Here is as close as I can get ...
Here is the xml I am using:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/new_bookmark_clock"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="12sp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/add" />
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/new_bookmark_name" />
</RelativeLayout>
Can anyone help me out?

You can better achieve it through LinearLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/new_bookmark_clock"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/add" />
</LinearLayout>

Try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/new_bookmark_clock"
android:layout_alignBaseline="#+id/btn_add_new_bookmark"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="wrap_content"
android:layout_alignBaseline="#+id/btn_add_new_bookmark"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/add" />
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/new_bookmark_name" />
</RelativeLayout>

you can use this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.5"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.3"
android:text="XXXXXXXXX" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.2"
android:text="Add" />
</LinearLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/new_bookmark_name" />
</LinearLayout>

Try with below
change android:layout_width="12sp" to android:layout_width="wrap_content"
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/new_bookmark_clock"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:text="xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="add" />
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/new_bookmark_name" />
</RelativeLayout>

The problem that you were providing fixed width to Textview which create problem, I just added one more Relative Layout which achieve your goal, have a look below code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_toRightOf="#+id/new_bookmark_name"
android:gravity="center"
android:text="xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_centerInParent=""
android:text="add" />
</RelativeLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/layout" />
</RelativeLayout>

try this one:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/add" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/new_bookmark_name" />
</LinearLayout>
</LinearLayout>

you can try it like this , this way it keeps your top_bar seperate from list view . Also for textview never use dp . Sp is used for text size.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id ="#+id/top_bar">
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/new_bookmark_clock"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="12sp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/add" />
</RelativeLayout
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

Related

Scrollview issue in xml, doesn't work

I have a following code.. I want to scroll my text area and my buttons within in LinearLayout. But my bottom button which is in relativelayout i want to stay it always in bottom not scroll able.
Thanks
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="175dip"
android:background="#android:color/white">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="20dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:textSize="15dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="55dp"
android:textSize="15dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:textSize="15dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="95dp"
android:textSize="15dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="115dp"
android:textSize="15dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="135dp"
android:textSize="15dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="155dp"
android:textSize="15dip"
/>
</RelativeLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Contact Us"/>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#android:color/black"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/buttonCheck"
android:layout_width="50sp"
android:layout_height="50sp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:background="#drawable/round_button"
android:text="Checked" />
</RelativeLayout>
</RelativeLayout>
As you are using relative layout, first put the button at the bottom of screen, and then let scrollview occupy the the height available.
Try following code:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/rel_btn_Check"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:background="#android:color/black" >
<Button
android:id="#+id/buttonCheck"
android:layout_width="50sp"
android:layout_height="50sp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/round_button"
android:text="Checked" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/rel_btn_Check"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="175dip"
android:background="#android:color/white" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="20dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:textSize="15dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="55dp"
android:textSize="15dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:textSize="15dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="95dp"
android:textSize="15dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="115dp"
android:textSize="15dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="135dp"
android:textSize="15dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="155dp"
android:textSize="15dip" />
</RelativeLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Contact Us" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
use this mechanism
set scroll view >
android:layout_weight="1"
and put footer :
android:layout_alignParentBottom="true"
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical">
<ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1">
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="jgfhrtuioghju oioupotyuhjipouipoi typ[ipo[ip[ijup0[ip0[ujiptjuip[juip[i]]]]]]] jogi5thjuohuortthjuo90uto okithjoitthjuo thjpo ktjhporyjohj ptlhjyjohjpy plthjoyjpokjotjhojuyojuhoithjoi kgjhoithoithjuotjupojutpo[ujotpotpojuote]ihihoihoi rguigreuighreiuyghir orighoihyheiyhreiygh oighoihtgihidrfyh8irfyhuesghuyhuiehvguyh rueighuyghuiyghieryhirgeyhi gorfihoihklrjegoij5oi hi thkoihioghoirhirhuiurg] th5yj u trjuykyu yjytku yktyu k ykj k y jiyku ykj yuk yku k y 6ty 6y 6yy kuiil 6 u67 uokityy7 i78o8 "/>
</ScrollView>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"><Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="rgfjughtih g5yujhoihuoi"/></LinearLayout></LinearLayout>

ScrollView control don't display more rows by scrolling

The tvReceiveNumber and tvOnlyOrExceptNumber controls have many rows, so I add a ScrollView control in my UI.
I think I can display more rows using ScrollView, but I failed, the ScrollView control don't scroll to diplay more rows.
How can I do? Thanks!
BTW, if you have better way to display many rows by scrolling screen and keep the toolbar buttons such as btnEdit, btnDeleet and btnClose always display on the bottom of screen, wolud you please tell me?
<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"
android:background="#drawable/border_ui" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="a15284e3e927f18"
ads:loadAdOnCreate="false" />
<LinearLayout
android:id="#+id/LinearLayoutName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adView"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvRuleNameTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rule Name" />
<TextView
android:id="#+id/tvRuleName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Rule Name" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutChecked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayoutName"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvEnabledRule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enabled Rule" />
<CheckBox
android:id="#+id/chEnabledRule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/LinearLayoutChecked" >
<LinearLayout
android:id="#+id/LinearLayoutOption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/tvReceiveTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Receiver"
/>
<TextView
android:id="#+id/tvReceiveNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1\n2\n3\n4\n5\n6\n7\n8\n9"/>
<TextView
android:id="#+id/tvOptionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forward Option" />
<TextView
android:id="#+id/tvOnlyOrExceptNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1\n2\n3\n4\n5\n6\n7\n8\n9\n10" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center_vertical"
android:background="#DCDCDC"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/btnEdit"
style="#style/myTextAppearance"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:checked="true"
android:text="Edit" />
<Button
android:id="#+id/btnDelete"
style="#style/myTextAppearance"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Delete" />
<Button
android:id="#+id/btnClose"
style="#style/myTextAppearance"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Close" />
</LinearLayout>
</RelativeLayout>
The following code is not good too. The toolbar buttons such as btnEdit, btnDeleet and btnClose can't always display on the bottom of screen, I need to scroll UI to display toolbar, and more some rows of the tvOnlyOrExceptNumber control disappear, I don't know why?
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="a15284e3e927f18"
ads:loadAdOnCreate="false" />
<LinearLayout
android:id="#+id/LinearLayoutName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adView"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvRuleNameTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rule Name" />
<TextView
android:id="#+id/tvRuleName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Rule Name" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutChecked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayoutName"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvEnabledRule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enabled Rule" />
<CheckBox
android:id="#+id/chEnabledRule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutOption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayoutChecked"
android:orientation="vertical" >
<TextView
android:id="#+id/tvReceiveTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Receiver"
/>
<TextView
android:id="#+id/tvReceiveNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1\n2\n3\n4\n5\n6\n7\n8\n9"/>
<TextView
android:id="#+id/tvOptionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forward Option" />
<TextView
android:id="#+id/tvOnlyOrExceptNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1\n2\n3\n4\n5\n6\n7\n8\n9\n10" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center_vertical"
android:background="#DCDCDC"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/btnEdit"
style="#style/myTextAppearance"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:checked="true"
android:text="Edit" />
<Button
android:id="#+id/btnDelete"
style="#style/myTextAppearance"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Delete" />
<Button
android:id="#+id/btnClose"
style="#style/myTextAppearance"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Close" />
</LinearLayout>
The result image
try this one :)
Edit:
the last line was not appearing :)
<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"
android:background="#drawable/border_ui">
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="a15284e3e927f18"
ads:loadAdOnCreate="false" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center_vertical"
android:background="#DCDCDC"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/btnEdit"
style="#style/myTextAppearance"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:checked="true"
android:text="Edit" />
<Button
android:id="#+id/btnDelete"
style="#style/myTextAppearance"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Delete" />
<Button
android:id="#+id/btnClose"
style="#style/myTextAppearance"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Close" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/adView"
android:id="#+id/scrollView1"
android:minWidth="25px"
android:minHeight="25px"
android:layout_above="#id/linearLayout1">
<RelativeLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout1">
<LinearLayout
android:id="#+id/LinearLayoutName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adView"
android:orientation="horizontal"
android:layout_alignParentTop="true">
<TextView
android:id="#+id/tvRuleNameTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rule Name" />
<TextView
android:id="#+id/tvRuleName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Rule Name" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutChecked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayoutName"
android:orientation="horizontal">
<TextView
android:id="#+id/tvEnabledRule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enabled Rule" />
<CheckBox
android:id="#+id/chEnabledRule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutOption"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayoutChecked">
<TextView
android:id="#+id/tvReceiveTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Receiver" />
<TextView
android:id="#+id/tvReceiveNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1\n2\n3\n4\n5\n6\n7\n8\n9" />
<TextView
android:id="#+id/tvOptionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forward Option" />
<TextView
android:id="#+id/tvOnlyOrExceptNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1\n2\n3\n4\n5\n6\n7\n8\n9\n10" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
ScrollView needs to be the root element in your xml. Add your elements to a LinearLayout or a RelativeLayout that is the first and only child of your ScrollView.

Heigth of ImageView

i want to add two imageViews in one layout, images i will set from galery (diferent size of image).Defaut images- all is ok. But when i set image from galery (image one)- a get a lot free space (image two)
2:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exrcise name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/et_exrcise_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Image"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="#+id/radio_anime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:onClick="onRadioButtonClicked"
android:text="anime" />
<RadioButton
android:id="#+id/radio_static"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:text="static" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/iv_image_one"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:scaleType="centerInside"
android:src="#drawable/btn_apply_oval_new" />
<ImageView
android:id="#+id/iv_image_two"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:scaleType="centerInside"
android:src="#drawable/btn_apply" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn_set_image_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/btn_set_image_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Muscle group"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner_muscle_group"
android:layout_width="wrap_content"
android:layout_height="45dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/et_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textMultiLine" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tecnique"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/et_tecnique"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textMultiLine" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn_save_exercise"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SAVE" />
<Button
android:id="#+id/test_anim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</LinearLayout>
</ScrollView>
try
android:adjustViewBounds="true"
It worked for a similar problem i've had some time ago.
have you tried to set the height of both the problematic linearLayout and the imageView to wrap_content?
also, have you tried to set a weight (to 1) to the problematic linearLayout and then set its height to 0px ?

Android - how to place buttons and spinners with linearlayout?

I have this code:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="85dp"
android:ems="10"
android:inputType="textPostalAddress"
android:text="neshto">
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<Button
android:id="#+id/buttonOk"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:text="Ok" />
<Button
android:id="#+id/buttonCancel"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:text="Cancel" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
<Spinner
android:id="#+id/size"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Spinner
android:id="#+id/color"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
I cant post image with the result I'm looking for, but I want the two buttons Ok and Cancel to be below, the two spinners to stand almost right down to the text field. But I can't handle these layouts. Can somebody give me an idea? I've tried it so many times, but it's still not looking the way I want.
Try this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="85dp"
android:ems="10"
android:inputType="textPostalAddress"
android:text="neshto" >
<requestFocus />
</EditText>
<Spinner
android:id="#+id/size"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Spinner
android:id="#+id/color"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<View
android:id="#+id/strut"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/buttonOk"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_gravity="center_horizontal"
android:layout_toLeftOf="#id/strut"
android:layout_weight="0.5"
android:text="Ok" />
<Button
android:id="#+id/buttonCancel"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="center_horizontal"
android:layout_toRightOf="#id/strut"
android:layout_weight="0.5"
android:text="Cancel" />
</RelativeLayout>
</LinearLayout>
Use a RelativeLayout instead of LinearLayout as layout container:
<?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" >
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="85dp"
android:ems="10"
android:inputType="textPostalAddress"
android:text="neshto" >
<requestFocus />
</EditText>
<Spinner
android:layout_below="#+id/editText"
android:id="#+id/size"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Spinner
android:layout_below="#+id/size"
android:id="#+id/color"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<Button
android:id="#+id/buttonOk"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:text="Ok" />
<Button
android:id="#+id/buttonCancel"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>

ListView pushes button out of screen

I'm trying to get the ListView to remain the same size even if it overflows. However, once the ListView overflows, it pushes the buttons below off the screen. How do I prevent it from pushing other elements that are below it?
As you can see from the above images, the second shows that the buttons get pushed off the screen once the ListView overflows.
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/splash_bg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:background="#color/splash_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20sp"
android:paddingBottom="10dp"
android:textColor="#color/splash_text"
android:text="#string/sub" />
<EditText
android:id="#+id/grp_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/field1"
android:lines="1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/members"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textSize="15sp"
android:paddingTop="5dp"
android:textColor="#color/splash_text"
android:text="#string/members" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/splash_bg"
android:orientation="horizontal" >
<EditText
android:id="#+id/name"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/field2" />
<Button
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:background="#color/splash_bg" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingTop="10dp" >
<Button
android:id="#+id/save_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="Save" />
<Button
android:id="#+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
Changet
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:background="#color/splash_bg" />
to
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:paddingLeft="5dp"
android:background="#color/splash_bg" />
You can use a relative layout for this. Modify the below according to your needs
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="11dp"
android:layout_marginTop="11dp"
android:text="Create New Group" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="23dp"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editText1"
android:layout_marginLeft="11dp"
android:layout_marginTop="18dp"
android:text="Members" />
<EditText
android:id="#+id/editText2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/textView1"
android:layout_below="#+id/textView2"
android:layout_marginTop="31dp"
android:ems="10" />
<ListView
android:id="#android:id/list"
android:layout_above="#+id/button1"
android:layout_below="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
/>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText2"
android:layout_alignBottom="#+id/editText2"
android:layout_alignParentRight="true"
android:layout_marginRight="13dp"
android:text="ADD" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/button3"
android:layout_below="#android:id/list"
android:text="Cancel" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/textView1"
android:text="Save" />
</RelativeLayout>
I added this line : android:layout_weight="1" to the LinearLayout where EditText exist (my problem source) and the problem is gone !
look at the code where I commented <!-- HERE!!! -->
LOL I know i'm very late to answer this Q ,, sorry ,, but for anyone who is still struggling !
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/linearLayout1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="ID : "
android:layout_margin="#dimen/EdgeMargins"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText"
android:layout_margin="#dimen/EdgeMargins"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayout2"
android:layout_weight="1"> <!-- HERE!!! -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Any Notes :"
android:id="#+id/textView2"
android:layout_margin="#dimen/EdgeMargins"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_margin="#dimen/EdgeMargins" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Done"
android:id="#+id/button"
android:layout_margin="#dimen/EdgeMargins" />
</LinearLayout>
i had my problem with the highlighted EditText in the pic ,,, it expands with the entered text and pushes the DONE Button down !
I know my solution may look so silly but I took a whole day to solve this !
Hope it helps ^_^ GL

Categories

Resources