Center view on horizontal middle of linearlayout - android

I'm trying to make a layout xml to fit like the layout below:
This layout goes in a row of listview.
The problem is: The thumbnail need to fit the middle of the row horizontally, and the star too, this is my layout xml with best approach:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:id="#+id/thumbnail"
android:src="#drawable/ic_thumbnail"
android:scaleType="fitXY"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/favoriteVendor"
android:layout_toRightOf="#+id/thumbnail">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NameNameNameNameNameNameName"
android:singleLine="true"
android:ellipsize="marquee"
android:id="#+id/vendorName"
android:textSize="20dp" />
<RatingBar
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pin_point_rating"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NameNameNameNameNaNameNameNameNameNameNameNamemeNameName"
android:id="#+id/vendorAddress"
android:singleLine="true"
android:ellipsize="marquee"/>
</LinearLayout>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/favoriteVendor"
android:adjustViewBounds="true"
android:textOn=""
android:textOff=""
android:background="#drawable/star"
android:scaleType="centerCrop"
android:layout_margin="8dp" android:layout_alignParentTop="true"
android:layout_alignParentRight="true" android:layout_alignParentEnd="true"/>
</RelativeLayout>
Does anyone know how to do it? I've tried lot of combinations

I guess a much better way to do this (This is just a layout, use padding as you wish)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"/>
<LinearLayout
android:layout_toRightOf="#+id/photo"
android:layout_toLeftOf="#+id/tb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"/>
<RatingBar
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pin_point_rating"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"/>
</LinearLayout>
<ToggleButton
android:id="#+id/tb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>

Try this way,hope this will help you to solve your problem,i have using LinearLayout to achieved your requirement.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/thumbnail"
android:src="#drawable/ic_thumbnail"
android:scaleType="fitXY"/>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NameNameNameNameNameNameName"
android:singleLine="true"
android:ellipsize="marquee"
android:id="#+id/vendorName"
android:textSize="20dp" />
<RatingBar
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pin_point_rating"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NameNameNameNameNaNameNameNameNameNameNameNamemeNameName"
android:id="#+id/vendorAddress"
android:singleLine="true"
android:ellipsize="marquee"
android:layout_marginTop="5dp"/>
</LinearLayout>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/favoriteVendor"
android:adjustViewBounds="true"
android:background="#drawable/star"
android:scaleType="centerCrop"
android:layout_marginLeft="5dp"/>
</LinearLayout>

Related

How to place a Textview to the right and center of the Imageview in Relative Layout

I want to place a textview to the right and gravity centre of the Image View. I am using Relative Layout for that. Using Relative Layout, i am able to set the Textview to the right side of the Image view.But not able to set it to the centre. I mean here center is not inside of the Imageview, i want to place Textview to the right centre of Imageview(outside centre of Imageview).I am not able to set to centre.
Anybody please help me out.I want to do this only in relative layout.
Here is my xml,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_width="match_parent">
<TextView
android:id="#+id/name_text_view"
android:textSize="20sp"
android:layout_toRightOf="#id/image_view"
android:layout_width="wrap_content"
android:textColor="#color/black"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
<ImageView
android:id="#+id/image_view"
android:layout_marginLeft="30dp"
android:layout_width="50dp"
android:layout_height="50dp"/>
<Button
android:id="#+id/button"
android:layout_centerHorizontal="true"
android:background="#color/blue"
android:textColor="#color/color_white"
android:layout_marginTop="20dp"
android:layout_below="#id/name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/val_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:layout_marginTop="20dp"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:layout_below="#id/button"/>
</RelativeLayout>
You can do it with this code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp">
<ImageView
android:id="#+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="center"
android:src="#drawable/ic_launcher_background" />
<TextView
android:id="#+id/name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/image_view"
android:layout_centerInParent="true"
android:text="hello world"
android:textColor="#color/black"
android:textSize="12sp" />
</RelativeLayout>
Use this code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_width="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
>
<ImageView
android:id="#+id/image_view"
android:layout_marginLeft="30dp"
android:layout_width="50dp"
android:layout_height="50dp"/>
<TextView
android:id="#+id/name_text_view"
android:textSize="20sp"
android:layout_toRightOf="#id/image_view"
android:layout_width="wrap_content"
android:textColor="#color/black"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
</LinearLayout>
<Button
android:id="#+id/button"
android:layout_centerHorizontal="true"
android:background="#color/blue"
android:textColor="#color/color_white"
android:layout_marginTop="20dp"
android:layout_below="#id/name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/val_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:layout_marginTop="20dp"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:layout_below="#id/button"/>
</RelativeLayout>
You can add this in your textview
android:layout_centerInParent="true"
Do You want this view? then try this code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_width="match_parent">
<LinearLayout
android:id="#+id/leaner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/image_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="30dp"
android:contentDescription="TODO"
app:srcCompat="#mipmap/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/val_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Value"
android:textColor="#android:color/black"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/leaner1"
android:layout_marginTop="1dp"
android:background="#android:color/holo_blue_dark"
android:text="button"
android:textColor="#android:color/white" />
</RelativeLayout>

How to align textView on layout center without conflict with other view?

I have an issue trying align textView to the center of layout: when I try to do this - it has a conflict with a button on the left - if text is too long - it become hidden under the button. Text length can be very different and I need it in the center of layout but not under/on the button.
Here is the xml file of activity layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_content_action_bar_layout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorBlue"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:autoText="false"
android:layout_centerInParent="true"
android:layout_alignWithParentIfMissing="false"
android:layout_alignParentRight="false" />
<ImageButton
android:layout_width="120dp"
android:layout_height="45dp"
android:id="#+id/item_content_back_button"
android:background="#drawable/back_button_selector"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginRight="5dp" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/item_content_scroll_view"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="125dp"
android:layout_height="125dp"
android:id="#+id/item_content_image"
android:src="#drawable/ic_no_thumbnail"
android:maxHeight="125dp"
android:maxWidth="125dp"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_subtitle"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Subtitle"
android:layout_alignTop="#+id/item_content_image"
android:layout_toRightOf="#+id/item_content_image"
android:layout_toEndOf="#+id/item_content_image"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_pubdate"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Date"
android:layout_below="#+id/item_content_subtitle"
android:layout_alignLeft="#+id/item_content_subtitle"
android:layout_alignStart="#+id/item_content_subtitle"
android:textSize="10dp"
android:layout_marginTop="10dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="blabla"
android:layout_below="#+id/item_content_pubdate"
android:layout_alignStart="#+id/item_content_pubdate"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Try using LinearLayout with layout-weight for this to avoid conflict. Change your first relativelayout to below one
<LinearLayout
android:id="#+id/item_content_action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="7">
<ImageButton
android:id="#+id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="2"
android:background="#drawable/chemist" />
<TextView
android:id="#+id/item_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="5"
android:autoText="false"
android:gravity="center"
android:maxLines="2"
android:singleLine="true"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/Black"
android:textStyle="bold" />
</LinearLayout>
Change Your RelativeLayout to LinearLayout and use android:layout_weight attribute of layout to do this.
<LinearLayout
android:id="#+id/item_content_action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1"
>
<ImageButton
android:id="#+id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/chemist" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="1"
android:autoText="false"/>
</LinearLayout>
Make the layout_gravity of the textview item_content_title as "center_horizontal".
And add android:layout_toLeftOf="#+id/item_content_title" under the ImageButton item_content_back_button.
Hope it was what you wanted.
Your Action bar layout has to be like this-
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_content_action_bar_layout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorBlue"
android:padding="10dp">
<ImageButton
android:layout_width="120dp"
android:layout_height="45dp"
android:id="#+id/item_content_back_button"
android:background="#drawable/back_button_selector"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dp" />
<TextView
android:toRightOf="#id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:autoText="false"
android:layout_centerInParent="true" />
</RelativeLayout>

Circle ImageView in the center of layout

Sorry for my english. I want to create a circle ImageView and i use this library all is well, but i can't locate this image in the center of my layout. I create to display in all screen Resolutions, and i use layout_weight if use layout_weight I can not put a static size image.
Bellow is my xml:
<RelativeLayout
android:layout_weight="0.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
>
<com.pkmmte.view.CircularImageView
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/p_img"
android:id="#+id/imageProfile"
android:layout_alignParentTop="true"
android:layout_gravity="center" />
</RelativeLayout>
The result of this code:
UPD:
my xml
<RelativeLayout
android:layout_weight="0.4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/p_edit_proofile"
android:id="#+id/editProfile"
android:layout_gravity="right"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<LinearLayout
android:layout_marginBottom="10dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_weight="0.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
>
<com.pkmmte.view.CircularImageView
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/p_img"
android:id="#+id/imageProfile"
android:layout_centAerInParent="true" />
</RelativeLayout>
<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text=""
android:id="#+id/nameProfile"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text=""
android:id="#+id/status" />
<TextView
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text="test"
android:textColor="#4fcc54"
android:id="#+id/aided" />
<LinearLayout
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text="PIN"
android:id="#+id/pin"
android:layout_gravity="center_vertical" />
<ImageView
android:layout_marginLeft="80dp"
android:src="#mipmap/p_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/key" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Use android:layout_centerInParent="true"
<com.pkmmte.view.CircularImageView
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/p_img"
android:id="#+id/imageProfile"
android:layout_centerInParent="true" />
This will center the image in your RelativeLayout
In your nested RelativeLayout remove android:layout_weight and add android:layout_gravity = "center".
Try to use android:gravity="center_horizontal"
<RelativeLayout
android:layout_weight="0.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
>
try to use this:
android:layout_centerInParent="true"
in the CircularImageView
Regards

Android Design 2 Images and text LinearLayout

I'm trying to create a layout like this:
Basically I have 2 Images that I would like to stick to either side of the LinearLayout and in the center have some text. I'm setting the width of the images in code based on the density of the screen, so that is of variable width.
Here is the code I have so far:
<RelativeLayout
android:id="#+id/user_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/user_loading_wrapper"
android:layout_alignWithParentIfMissing="true"
android:layout_alignParentTop="true"
android:layout_margin="#dimen/default_spacing">
<!--User Poster-->
<ImageView
android:id="#+id/user_poster"
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitXY"
android:contentDescription="User Poster"
android:layout_alignParentLeft="true"/>
<!--Review Details-->
<LinearLayout
android:id="#+id/screen_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/user_poster"
android:layout_alignParentTop="true"
android:gravity="center"
android:layout_centerInParent="true"
android:layout_marginLeft="#dimen/default_spacing_max"
android:orientation="vertical">
<!--User Title-->
<TextView
android:id="#+id/user_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#333"
android:singleLine="false"
android:layout_gravity="center"/>
<!--Location-->
<TextView
android:id="#+id/user_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#333"
android:singleLine="false"
android:layout_gravity="center"/>
<!--User 2 Title-->
<TextView
android:id="#+id/user_secondary_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#333"
android:layout_marginTop="4dp"
android:singleLine="false"
android:layout_gravity="center"
tools:text="Life of Pi"/>
</LinearLayout>
<!--Poster-->
<ImageView
android:id="#+id/user_poster_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitEnd"
android:layout_toRightOf="#id/screen_details"
android:contentDescription="Poster"
android:layout_alignParentRight="true"/>
</RelativeLayout>
But it doesn't work at all. I want the Center Layout to expand and occupy all the space in the middle between the two images.
i fixed it .... check output it in image and flow in code.
And Code is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/user_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true" >
<ImageView
android:id="#+id/user_poster"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#android:color/black"
android:scaleType="fitXY" />
<LinearLayout
android:id="#+id/screen_details"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/user_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#android:color/darker_gray"
android:paddingLeft="10dp"
android:singleLine="false"
android:text="Life of Pi"
android:textColor="#333" />
<TextView
android:id="#+id/user_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="4dp"
android:background="#android:color/darker_gray"
android:paddingLeft="10dp"
android:singleLine="false"
android:text="Life of Pi"
android:textColor="#333" />
<TextView
android:id="#+id/user_secondary_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="4dp"
android:background="#android:color/darker_gray"
android:paddingLeft="10dp"
android:singleLine="false"
android:text="Life of Pi"
android:textColor="#333" />
</LinearLayout>
<ImageView
android:id="#+id/user_poster2"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_weight="0"
android:background="#android:color/black"
android:scaleType="fitXY" />
</LinearLayout>
try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/user_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_alignParentTop="true"
android:layout_margin="5dp">
<!--User Poster-->
<ImageView
android:id="#+id/user_poster"
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitXY"
android:contentDescription="User Poster"
android:layout_alignParentLeft="true"/>
<!--Review Details-->
<LinearLayout
android:id="#+id/screen_details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="70dp"
android:layout_toRightOf="#id/user_poster"
android:gravity="center"
android:orientation="vertical" >
<!--User Title-->
<TextView
android:id="#+id/user_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#333"
android:singleLine="false"
android:layout_gravity="center"/>
<!--Location-->
<TextView
android:id="#+id/user_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#333"
android:singleLine="false"
android:layout_gravity="center"/>
<!--User 2 Title-->
<TextView
android:id="#+id/user_secondary_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#333"
android:layout_marginTop="4dp"
android:singleLine="false"
android:layout_gravity="center"
android:text="Life of Pi"/>
</LinearLayout>
<!--Poster-->
<ImageView
android:id="#+id/user_poster_2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:contentDescription="Poster" />
</RelativeLayout>

My layout eats the last image

I have this layout for my row in a listview... last image is not displayed... why?
<?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="70dip"
android:background="#android:color/black">
<ImageView
android:id="#+id/img"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_gravity="center"
android:layout_marginLeft="5dip"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="#+id/title"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginLeft="10dip"
android:layout_marginTop="1dip"/>
<TextView android:id="#+id/description"
android:typeface="sans"
android:textSize="12sp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ellipsize="end"
android:layout_weight="0"
android:layout_marginLeft="10dip"/>
<TextView android:id="#+id/variable"
android:textSize="12sp"
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:lines="1"
android:ellipsize="end"
android:layout_weight="0"
android:layout_marginLeft="10dip"/>
</LinearLayout>
<ImageView
android:id="#+id/img"
android:src="#drawable/disclosure"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_gravity="center"
android:layout_marginLeft="5dip"/>
</LinearLayout>
Thanks in advance,
regards
EDIT: Try using a relativelayout so you don't have to have a linearlayout in the middle. I also have a three columnish thing going on so it should be similar for you.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id ="#+id/container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="62dp"
android:cacheColorHint="#ff000000"
android:background="#color/white"
android:clickable="true"
>
<ImageView
android:layout_height="60dp"
android:layout_width="60dp"
android:id="#+id/thumbnail"
android:layout_marginRight="10dp"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:layout_marginLeft="2dp"
android:layout_centerVertical="true"
android:scaleType="fitXY"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingRight="10dp"
android:layout_toRightOf="#id/thumbnail"
android:textSize="13dp"
android:textStyle="bold"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_alignTop = "#id/thumbnail"/>
<TextView
android:id="#+id/merchant"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingRight="10dp"
android:layout_toRightOf="#id/thumbnail"
android:textSize="12dp"
android:textStyle="normal"
android:textColor="#000000"
android:ellipsize="end"
android:focusable="true"
android:lines="1"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"/>
<TextView
android:id="#+id/distance"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="#id/merchant"
android:layout_toRightOf="#id/priceButton"
android:textColor="#color/black"
/>
<Button
android:id="#+id/priceButton"
android:layout_height="60dp"
android:layout_width="70dp"
android:textColor="#color/white"
android:textSize="14dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
/>
</RelativeLayout>
With no screenshot I would imagine you just have too much data on the screen , use a scrollview to allow the user to scroll.
Also why is your root layout's height limited to 70? Why dont you use fill_parent or match_parent

Categories

Resources