Android RelativeLayout position items - android

The following image is what I'm trying to reach as final result:
My code so far works great on aligning the buttons in center:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageButton
android:id="#+id/button_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/my_border"
android:layout_marginTop="25dp"
android:src="#drawable/categories" />
<ImageButton
android:id="#+id/button_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/button_A"
android:layout_marginLeft="34dp"
android:layout_marginTop="25dp"
android:background="#drawable/my_border"
android:src="#drawable/shopping_cart" />
</RelativeLayout>
Then, after the "button_B" I tried to achieve the message "TEXT HERE IN CENTER" without success.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TEXT HERE IN CENTER"/>
</RelativeLayout>
Any ideas? Thanks.
Edit: Solved. http://pastebin.com/9DwaQrPq

add the attributes
android:layout_centerInParent="true"
android:layout_below="id of thing you want it below"
to the text view
also take the text view out of the inner Relative Layout
EDIT
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/itemRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clickable="false">
<ImageButton
android:id="#+id/button_A"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/my_border"
android:layout_marginTop="25dp"
android:src="#drawable/categories" />
<ImageButton
android:id="#+id/button_B"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/button_A"
android:layout_marginLeft="34dp"
android:layout_marginTop="25dp"
android:background="#drawable/my_border"
android:src="#drawable/shopping_cart" />
</LinearLayout>

Take your TextView out of this inner RelativeLayout and give it the property and add a gravity to it to center your text.
<TextView
android:id="#+id/txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:text="TEXT HERE IN CENTER"/>
If this doesn't work then please explain what you are getting or what isn't working about it. Also, a picture of what you currently are getting would help.
Edit
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
<ImageButton
android:id="#+id/button_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/my_border"
android:layout_marginTop="25dp"
android:src="#drawable/categories" />
<ImageButton
android:id="#+id/button_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/button_A"
android:layout_marginLeft="34dp"
android:layout_marginTop="25dp"
android:background="#drawable/my_border"
android:src="#drawable/shopping_cart" />
</LinearLayout>
<TextView
android:id="#+id/txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:text="TEXT HERE IN CENTER"/>
</RelativeLayout>

Related

show TextView and Button on the ImageView

Want to show the TextView and Button on the ImageView I try but ImageView hides the Button and TextView Help me what I can do I try it in different Layouts I update the new code but same issue face
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY" >
</ImageView>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/imageview"
>
</RelativeLayout>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/btn_booking"
android:layout_gravity="right"
android:gravity="bottom"
android:layout_alignBottom="#+id/text_booking"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/text_booking"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Use a RelativeLayout as your root layout:
<?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">
<ImageView
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY" >
</ImageView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/text_booking"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/btn_booking"
android:layout_gravity="right"
android:gravity="bottom"
android:layout_marginLeft="180dp"/>
</LinearLayout>
</RelativeLayout>
look at my code i recently use it i use the parent layout(RelativeLayout) and set the bacground image for parent layout also i change background in java and inside parent layout add images and text what you want.......!
hope it will help you.
<RelativeLayout
android:id="#+id/frontLay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/note0">
<TextView
android:id="#+id/imageOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="50dp"
android:background="#drawable/onecircle"
android:tag="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:id="#+id/imageTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/imageOne"
android:layout_alignRight="#+id/imageOne"
android:layout_below="#+id/imageOne"
android:layout_marginEnd="17dp"
android:layout_marginRight="17dp"
android:layout_marginTop="15dp"
android:background="#drawable/twocircle"
android:tag="2"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:id="#+id/imageThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageTwo"
android:layout_marginLeft="35dp"
android:layout_marginStart="35dp"
android:layout_toEndOf="#+id/imageSix"
android:layout_toRightOf="#+id/imageSix"
android:background="#drawable/threecircle"
android:tag="3"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:id="#+id/imageFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageTwo"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/imageTwo"
android:layout_marginTop="29dp"
android:background="#drawable/fourcircle"
android:tag="4"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:id="#+id/imageFive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imageTwo"
android:layout_toLeftOf="#+id/imageEight"
android:layout_toStartOf="#+id/imageEight"
android:background="#drawable/fivecircle"
android:tag="5"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="25dp"
android:textStyle="bold"
android:visibility="invisible" />
</RelativeLayout>
1) Change your Main LinearLayout (First one) to RelativeLayout
2) In your Sub LinearLayout (Second one) use -
android:layout_above="#+id/imageview"
android:alignParentBottom="true"
UPDATE
Please Check it -
<?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">
<ImageView
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#mipmap/ic_launcher"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/imageview"
android:alignParentBottom="true"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/text_booking"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/btn_booking"
android:weight="1"/>
</RelativeLayout>
Hope it will help :)
Just add these two lines and my issue is resolved.
android:layout_toLeftOf="#+id/btn_booking"
android:layout_toStartOf="#+id/btn_booking"
strange everyone suggested to you to use RelativeLayout while you should use FrameLayout for this kind of stuff. its pretty easy to achieve that with FrameLayout rather than RelativeLayout as the RelativeLayout is pretty expensive when it comes to drawing. to achieve what you asking for you should use this simple combination:
FrameLayout>ImageView>LinearLayout(with layout_gravity){Button,TextView}/>

relative layout gravity center not aligning correctly

I'm trying to center the chilldren of my relative layout in the center of my screen but it's acting like it's aligned to the top of the parent and I can't figure out why.
my .XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#f70909">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:src="#drawable/dice"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textMessage"
android:layout_centerHorizontal="true"
android:layout_below="#+id/imageView2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="#+id/textMessage" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_below="#+id/editUserSplash" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash"
android:layout_centerHorizontal="true"
android:layout_below="#+id/editPasswordSplash" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/prgSplash"
style="#android:style/Widget.DeviceDefault.ProgressBar.Large"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:layout_below="#+id/btnSplash" />
</RelativeLayout>
I've tried making the parent a relativelayout without success and it won't align to the bottom either. Initially I thought the layout wasn't filling the whole screen but since its height and width are match_parent I don't think that's the problem. in android studio it is displaying correctly though so I must be missing something small.
I also tried using the gravity and layoutgravity parameters and a combination of the two but without success
Edit: I need the views to stay in the same formation relative to each other but centered in the screen vertically.
Edit 2:I set the background of the RelativeLayout to red and got this: So the relativelayout isn't filling my screen.
Edit 3:
Edit 4:
try this:
<?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"
android:background="#f70909">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:src="#drawable/dice"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textMessage"
android:layout_centerHorizontal="true"
android:layout_below="#+id/imageView2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="#+id/textMessage" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_below="#+id/editUserSplash" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash"
android:layout_centerHorizontal="true"
android:layout_below="#+id/editPasswordSplash" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/prgSplash"
style="#android:style/Widget.DeviceDefault.ProgressBar.Large"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:layout_below="#+id/btnSplash" />
</RelativeLayout>
</RelativeLayout>
Try something like this.
<?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">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:layout_centerInParent="true"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_centerInParent="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textMessage" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:gravity="center" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:gravity="center" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/prgSplash"
style="#android:style/Widget.DeviceDefault.ProgressBar.Large"
android:indeterminate="true" />
</LinearLayout>
</RelativeLayout>
UPDATE:
If setting the xml in an AlertDialog, it's possible that there is a space allotted at the bottom. I google and found this alert_dialog.xml for reference. It seems that there is a buttonPanel at the bottom with a minimum height of 54dip.
<LinearLayout android:id="#+id/buttonPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="54dip"
android:orientation="vertical" >
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="4dip"
android:paddingStart="2dip"
android:paddingEnd="2dip"
android:measureWithLargestChild="true">
<LinearLayout android:id="#+id/leftSpacer"
android:layout_weight="0.25"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" />
<Button android:id="#+id/button1"
android:layout_width="0dip"
android:layout_gravity="start"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<Button android:id="#+id/button3"
android:layout_width="0dip"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<Button android:id="#+id/button2"
android:layout_width="0dip"
android:layout_gravity="end"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<LinearLayout android:id="#+id/rightSpacer"
android:layout_width="0dip"
android:layout_weight="0.25"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
I think this may help you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center">
<RelativeLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/textMessage"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:layout_below="#+id/textMessage"
android:gravity="center" />
<EditText
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:layout_below="#+id/editUserSplash"
android:gravity="center" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash"
android:layout_below="#+id/editPasswordSplash"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Thanks to ank I was able to figure out that the reason why the RelativeLayout didn't fill my screen is that I used it in an alertDialog. So RelativeLayouts parent isn't the screen but the alertDialog. Since an alertDialog wraps its content it doesn't fill the entire screen.

android LinearLayout - ImageView gets pushed off the screen

I use the layout posted below to show messages by inflating that layout as a row into a ListView. The problem is that it works fine with a single-line message but when there are 2 lines or more the ImageView indicating the message state gets pushed off the screen, can't get the reason. Any ideas? Layout code and screenshot below.
That is the inflated layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp" >
<TextView
android:id="#+id/tvTimestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="8sp" />
<LinearLayout
android:id="#+id/rl_message_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toRightOf="#+id/tvTimestamp"
android:background="#drawable/outgoing_bg"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvMessageOutgoing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imgMessageState"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="bottom"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</RelativeLayout>
change you linear layout width fill_parent
and add android:layout_weight="1" in textview
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:id="#+id/tvTimestamp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20"
android:gravity="center_vertical"
android:text="10:20pm"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="8sp" />
<RelativeLayout
android:id="#+id/rl_message_holder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="80" >
<TextView
android:id="#+id/tvMessageOutgoing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/imgMessageState"
android:padding="4dp"
android:singleLine="false"
android:text="android developer tutorial in the world"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imgMessageState"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="bottom"
android:contentDescription="#string/app_name"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
</LinearLayout>
This worked for me
<TextView
android:id="#+id/tvMessageOutgoing"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="4dp"
android:layout_weight="1"
android:text="Medium Tesssssssssssssssssssssssssssssseeeeeeeessssxt"
android:textAppearance="?android:attr/textAppearanceMedium" />
It gives the textview the remaining space.
Try like this
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.6"
>
<ImageView
android:id="#+id/imgMessageState"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="bottom"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Define your image view layout inside of Linear Layout
You can use
android:drawableRight="#drawable/ic_launcher"

ListView Row Height Too Small

Below is an image of a ListView row that is too short. I've tried too many combinations and yield my frustration to StackOverflow.
How can I fix this and show the whole row? Here is the XML for the item.
<?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="fill_parent"
android:weightSum="1">
<LinearLayout android:id="#+id/item_left"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingRight="2dp"
android:paddingLeft="2dp"
android:background="#drawable/item_left"
android:layout_gravity="fill_vertical">
<TextView
android:id="#+id/status_day"
android:layout_gravity="center_vertical"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:textColor="#color/item_left_text"
android:textSize="25sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="2dp"
android:background="#drawable/item_right"
android:layout_weight="1">
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/item_right_text"
android:text="" />
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/item_right_text"
android:text="" />
</LinearLayout>
<ImageButton
android:id="#+id/options"
android:background="#drawable/item_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_moreoverflow_normal_holo_light"
/>
</LinearLayout>
Any help is appreciated.
can you use this, set row layout height
android:layout_height="?android:attr/listPreferredItemHeight"
I set the height of the ImageButton to match_parent.
This fixed the issue oddly. Sigh.
your layout should be in such manner for your requirement i have pasted not same as your's layout but related to it check it
<?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" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="60dp" >
<ImageView
android:id="#+id/ivArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:focusable="false"
android:clickable="false"
android:src="#drawable/arrow" />
<RelativeLayout
android:id="#+id/ivIcon"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:focusable="false"
android:clickable="false"
android:background="#drawable/oddnumbg" >
<TextView
android:id="#+id/tvNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:textColor="#color/ReceiptNoLable"
android:text="No." />
<TextView
android:id="#+id/tvReceiptNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:singleLine="true"
android:layout_below="#+id/tvNo"
android:gravity="center"
android:textColor="#color/ReceiptSavedColor"
android:textSize="18dp"
android:text="1234" />
</RelativeLayout>
<TextView
android:id="#+id/tvSubName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/ivIcon"
android:text="RECEIVED FROM"
android:gravity="center"
android:focusable="false"
android:clickable="false"
android:textColor="#color/ReceiptNoLable"
/>
<TextView
android:id="#+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/ivIcon"
android:layout_below="#+id/tvSubName"
android:text="RECEIPT"
android:layout_marginLeft="15dp"
android:textColor="#color/ReceiptSavedColor"
android:textSize="30dp"
android:focusable="false"
android:layout_toLeftOf="#+id/tvReceiptPrize"
android:clickable="false"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvReceiptPrize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/ivArrow"
android:background="#drawable/myreceiptprizebg"
android:gravity="center"
android:singleLine="true"
android:layout_marginRight="5dp"
android:textSize="20dp"
android:textColor="#fff"
android:text="$84.20" />
</RelativeLayout>
</LinearLayout>
just set the height of the outer layout, instead of using fill_parent
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:awesome="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height=50dp <!-- or anything which fits -->

Fit two textView in LinearLayout next to an ImageView

I have this layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/fill_parent"
android:background="#color/white"
android:padding="2dip">
<ImageView
android:id="#+id/img_album"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:layout_centerVertical="true"
android:padding="5dp"
/>
<LinearLayout
style="#style/fill_parent"
android:orientation="horizontal"
android:layout_toRightOf="#id/img_album"
android:layout_centerVertical="true">
<TextView
android:id="#+id/album_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#color/black"
android:layout_marginRight="10dp"
/>
<TextView
android:id="#+id/picts_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
/>
</LinearLayout>
</RelativeLayout>
Which gives me this image:
I dont know why I dont get the title of the album and next the number of picts.
Well, I did something using layout_weight property as:
<TextView
android:id="#+id/album_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#color/black"
android:layout_marginRight="10dp"
android:layout_weight="1"
/>
<TextView
android:id="#+id/picts_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:layout_weight="1" />
And I dont really know why, I get now the number, next to the title, as
Could someone tell me:
Why I dont get the number in the 1st scenario, but I do in the 2nd.
How to expand the text all the width of the Linearyout, so the
second Text "Smartphones..." doesnt get stretch, but fits its
parent.
Thanks!
Using the width = 0dip and weigth = 1. I did it!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/fill_parent"
android:background="#color/white"
android:padding="2dip">
<ImageView
android:id="#+id/img_album"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:layout_centerVertical="true"
android:padding="5dp"
/>
<LinearLayout
style="#style/fill_parent"
android:orientation="horizontal"
android:layout_toRightOf="#id/img_album"
android:layout_centerVertical="true"
android:id="#+id/album_details">
<TextView
android:id="#+id/album_title"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#color/black"
android:layout_marginRight="30dp"
android:textSize="17sp"
android:layout_weight="1"
/>
<TextView
android:id="#+id/picts_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:layout_weight="0"
android:textSize="17sp"
android:layout_gravity="right"
android:layout_marginRight="10dp"
/>
</LinearLayout>
</RelativeLayout>
Try to make it with a FrameLayout rather than a RelativeLayout. It's really easier to build your layout with this. Something like this, but with size and style adaptation :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:padding="2dp">
<ImageView
android:id="#+id/img_album"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_marginRight="6dp"
android:cropToPadding="true"
android:layout_centerVertical="true"
android:padding="5dp"
/>
<TextView
android:id="#+id/album_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_gravity="center"
android:singleLine="true"
android:textColor="#color/black"
android:layout_marginRight="50dp"
/>
<TextView
android:id="#+id/picts_number"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:textColor="#color/black"
/>
</FrameLayout>

Categories

Resources