UPDATE: I've opened a new thread with my updated question here:
Android - How to display 4 text views with Icons?
Thank you for your answers, I'd really appreciate it if you could help me with my newer thread above.
I'm trying to display 4 text views at the bottom of the screen but I can't figure out how to that that. Every time I try to move one button it screws up the rest.
Here's what it currently looks like:
Here's my manuel marks as to where I want to position the buttons (Each line represents a text view item position):
Here's the current code, any pointers would be really great:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity" >
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true" >
</android.support.v4.view.ViewPager>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="124dp"
android:layout_toRightOf="#+id/ButtonRate"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_alignRight="#+id/ButtonWallpaper"
android:text="TextView" />
<TextView
android:id="#+id/ButtonWallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView2"
android:layout_marginRight="50dp"
android:layout_marginTop="137dp"
android:clickable="true"
android:onClick="setWallpaper"
android:text="#string/set_wallpaper"
android:textColor="#color/red" />
<TextView
android:id="#+id/ButtonRate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/ButtonWallpaper"
android:layout_alignBottom="#+id/ButtonWallpaper"
android:layout_alignParentLeft="true"
android:layout_marginLeft="50dp"
android:clickable="true"
android:onClick="rate"
android:text="#string/rate_button"
android:textColor="#color/red" />
I'm really stuck.
Thanks very much in advance,
Dvir
You need to put another relative layout after ViewPager for your textViews, and add android:layout_alignParentBottom="true" to that Layout like this:
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true" >
</android.support.v4.view.ViewPager>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/ButtonRate"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_alignRight="#+id/ButtonWallpaper"
android:text="TextView" />
<TextView
android:id="#+id/ButtonWallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView2"
android:layout_marginRight="50dp"
android:clickable="true"
android:onClick="setWallpaper"
android:text="hello" />
<TextView
android:id="#+id/ButtonRate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/ButtonWallpaper"
android:layout_alignBottom="#+id/ButtonWallpaper"
android:layout_alignParentLeft="true"
android:layout_marginLeft="50dp"
android:clickable="true"
android:onClick="rate"
android:text="hello2" />
</RelativeLayout>
Also note that I've deleted android:layout_marginTop parameters, you can adjust it, if you wish
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
You can do something like that :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="394dp"
android:adjustViewBounds="true" >
</android.support.v4.view.ViewPager>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/ButtonRate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="39dp"
android:text="ButtonRate" />
<TextView
android:id="#+id/ButtonWallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="60dp"
android:text="ButtonWallpaper" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_alignLeft="#+id/ButtonWallpaper"
android:layout_marginLeft="22dp"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/ButtonRate"
android:layout_centerVertical="true"
android:text="TextView" />
</RelativeLayout>
Related
There is a RelativeLayout with a nested LinearLayout that contains two TextViews positioned horizontally relative to each other. This is DiscountAmount and AmountWithDiscount.
I need to keep the DiscountAmount and AmountWithDiscount always at the same level vertically, for this I put the android property in LinearLayout: android:layout_below = "# + id / textViewRowQuantity". But if the Name is too long and takes three lines, then it will go to DiscountAmount. If Name takes no more than 2 lines, then all is well.
Tell me, please, how can I solve this problem?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayoutSaleListRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="#+id/imageViewRemoveRowSale"
android:layout_width="#dimen/size_30px"
android:layout_height="#dimen/size_30px"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:src="#drawable/ic_action_remove"/>
<RelativeLayout
android:id="#+id/relativeLayoutIncQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_toRightOf="#+id/imageViewRemoveRowSale"
android:layout_toLeftOf="#+id/imageViewEditRowSale"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewRowPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRowPrice"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/textViewRowPrice"
android:text="TextView" />
<LinearLayout
android:id="#+id/layoutDiscount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRowQuantity"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewRowDiscountAmount"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowAmountWithDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:text="TextView" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="#+id/imageViewEditRowSale"
android:layout_width="#dimen/size_45px"
android:layout_height="#dimen/size_45px"
android:layout_marginTop="5dp"
android:layout_alignParentRight="true"
android:src="#drawable/ic_action_edit" />
Add result:
Implemented through ConstraintLayout. Thanks to all.
You can limit the number of lines in the TextView to 2 by adding this lines:
android:ellipsize="end"
android:lines="2"
End ellipsize end means if the text is so long then it will be replaced with three dots ...
if you want to show AmountWithDiscount is below to discount then change liner layout orientation like below .
android:orientation="vertical"
Try this :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayoutSaleListRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="#+id/imageViewRemoveRowSale"
android:layout_width="#dimen/size_30px"
android:layout_height="#dimen/size_30px"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:src="#drawable/ic_action_remove"/>
<RelativeLayout
android:id="#+id/relativeLayoutIncQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_toRightOf="#+id/imageViewRemoveRowSale"
android:layout_toLeftOf="#+id/imageViewEditRowSale"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewRowPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRowPrice"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/textViewRowPrice"
android:text="text"
android:minLines="2"/>
<LinearLayout
android:id="#+id/layoutDiscount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRowName"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewRowDiscountAmount"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowAmountWithDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:text="TextView" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="#+id/imageViewEditRowSale"
android:layout_width="#dimen/size_45px"
android:layout_height="#dimen/size_45px"
android:layout_marginTop="5dp"
android:layout_alignParentRight="true"
android:src="#drawable/ic_action_edit" />
</RelativeLayout>
Hope this helps
make some change in liner layout..
<LinearLayout
android:id="#+id/layoutDiscount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRowQuantity"
android:orientation="horizontal"
android:weightSum="1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3">
<TextView
android:id="#+id/textViewRowDiscountAmount"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:singleLine="true"
android:text="TextViewsdfsdfdsgfd" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7">
<TextView
android:id="#+id/textViewRowAmountWithDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:singleLine="true"
android:layout_marginRight="5dp"
android:text="textview" />
</LinearLayout>
</LinearLayout>
You can try out this below code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayoutSaleListRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="#+id/imageViewRemoveRowSale"
android:layout_width="#dimen/size_30px"
android:layout_height="#dimen/size_30px"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:src="#drawable/ic_action_remove"/>
<RelativeLayout
android:id="#+id/relativeLayoutIncQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_toRightOf="#+id/imageViewRemoveRowSale"
android:layout_toLeftOf="#+id/imageViewEditRowSale"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rr_layout">
<TextView
android:id="#+id/textViewRowPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRowPrice"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/textViewRowPrice"
android:text="TextView" />
</RelativeLayout>
<LinearLayout
android:id="#+id/layoutDiscount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rr_layout"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewRowDiscountAmount"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowAmountWithDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:text="TextView" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="#+id/imageViewEditRowSale"
android:layout_width="#dimen/size_45px"
android:layout_height="#dimen/size_45px"
android:layout_marginTop="5dp"
android:layout_alignParentRight="true"
android:src="#drawable/ic_action_edit" /></RelativeLayout>
I have created an Android Application in that I have problem in Layout design.
Please see layout in this link-
https://lh6.googleusercontent.com/WJRLolp6PVoKskRBdFH6VMmdqftSgt10EZhd-A1h_glblYoJjVrF8bYjsPXmw752sGttlzIh7IHwtQo=w1342-h479
My code:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/product_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/product" />
<TextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/product_image"
android:layout_alignParentRight="true"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<ImageView
android:id="#+id/user_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/userimage" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="#+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Distance"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
Thanks.
<ImageView
android:id="#+id/user_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:layout_marginTop="-25dp"
android:src="#drawable/ic_launcher" />
change the user image xml to above code and try
You can use the Relative layout for that
or
you can make it custom layout
http://www.vogella.com/tutorials/AndroidCustomViews/article.html
I have layout with few text boxes and checkboxes. Between them is listview. When I add three or more items I can't see them in listview, the listview does not have scroll bar.
This is my layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text" />
<EditText
android:id="#+id/editText"
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="New Text" />
<EditText
android:id="#+id/editText2"
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="New Text" />
<EditText
android:id="#+id/editText3"
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="New Text" />
<EditText
android:id="#+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="163dp"
android:orientation="horizontal" >
<!-- -------------HERE IS MY LISTVIEW--------------- -->
<ListView
android:id="#+id/listView"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutCheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/linearLayoutGlavni"
android:layout_below="#+id/linearLayoutGlavni"
android:layout_weight="1"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reklamacija dobavljaču" />
<CheckBox
android:id="#+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="14dp"
android:layout_toRightOf="#+id/checkBox"
android:text="Prenamjena robe" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<CheckBox
android:id="#+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Otpis robe" />
<CheckBox
android:id="#+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="111dp"
android:layout_toRightOf="#+id/checkBox3"
android:text="Upozorenje djelatniku" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<CheckBox
android:id="#+id/checkBox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Obuka djelatnika" />
<CheckBox
android:id="#+id/checkBox6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="64dp"
android:layout_toRightOf="#+id/checkBox5"
android:text="Održavanje" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text" />
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.68" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Is there something missing inside layout code or this must be solved through code?
You should never put a listview in a scrollView, because Listview is autoScrollable when its size increases than the screen.
Please refer to this link. Makers of Listview component.
Here you can find the best approaches of How to use a listview properly
https://www.youtube.com/watch?v=wDBM6wVEO70
I could suggest you to put only the ListView in a ScrollView. I think it will work, because I already tried it. So please try with something like this
<ScrollView
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="163dp"
<ListView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/listView" />
</ScrollView>
I have a Back button on the top of my layout and i have placed the label text after that button. i need to center the label text, so that it should resemble like layout heading.Can anyone guide me on this task.
Hope u r looking for this
<RelativeLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#0fa2da" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Text View"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="23sp" />
<Button
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="#drawable/white_bar" />
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:background="#148cba"
android:onClick="goBack"
android:text="Back"
android:textColor="#fff" />
</RelativeLayout>
Use this one:
<?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" >
<RelativeLayout
android:layout_width="match_parent"
android:background="#ff0000"
android:layout_height="60dp" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Back" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_centerHorizontal="true"
android:text="Attractions"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</LinearLayout>
Edited Code as per your response
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rlt1"
android:orientation="horizontal"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#24a6c6">
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:src="#drawable/back_btn_img" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Attractions"
android:textColor="#fff"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
In RelativeLayout try to set your TextView as android:center_horizontal="true"
I am trying to create a header that is a little similar to the facebook android app. The header should have a header title in the middle with a button on each side.
I have the header title but my code below does not show either button. I'm not sure if this info helps but the TableRow layout for this header is taking up a lot of height space. It used to wrap the until the title's height until I attempted adding buttons.
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#008000" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/menuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/HeaderTextView"
android:text="Button" />
<TextView
android:id="#+id/HeaderTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/header"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:textColor="#FFF"
android:textStyle="italic" />
<Button
android:id="#+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/HeaderTextView"
android:text="Button" />
</RelativeLayout>
</TableRow>
</TableLayout>
This works for me. For what ever reason, the android:layout_weight="1" makes it work.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="#+id/menuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Button" />
<TextView
android:id="#+id/HeaderTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="This is the title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFfff"
android:textStyle="italic" />
<Button
android:id="#+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Button" />
</RelativeLayout>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" >
<Button
android:id="#+id/menuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Button" />
<TextView
android:id="#+id/HeaderTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toRightOf="#id/menuButton"
android:layout_toLeftOf="#+id/infoButton"
android:text="headersfasfsdfsdfsdfsdfsdf"
android:textColor="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:textStyle="italic" />
<Button
android:id="#+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Button" />
</RelativeLayout>
</TableLayout>