I'm trying to add an ImageButton at first, and here is the XML that contains it:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:id="#+id/name_search_layout"
android:background="#android:color/darker_gray"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/label_name"
android:text="#string/name_label"
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/text_name"
android:hint="#string/name_hint"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_expand"
android:layout_gravity="right"
android:src="#android:drawable/btn_plus"
/>
</LinearLayout>
This is inside another LinearLayout, but my button don't appear, it shows like this:
How can i make it appear?
Your imageButton not show, because, the width of EditText is match_parent, please change it to wrap_content like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:id="#+id/name_search_layout"
android:background="#android:color/darker_gray">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/label_name"
android:text="#string/name_label"
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textStyle="bold" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text_name"
android:hint="#string/name_hint"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button_expand"
android:layout_gravity="right"
android:src="#android:drawable/btn_plus"
/>
Related
I want to achieve this layout as in screenshot: ImageView + 2 lines of Textview -> left aligned, and in the same row I want to add another textView, but at the right end of the line.
What I tried:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="vertical">
<ImageView
android:id="#+id/imageViewIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_alignParentStart="true"
android:paddingEnd="10dp"
android:paddingStart="10dp"
/>
<TextView
android:id="#+id/book_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageViewIcon"
android:textSize="16sp"
android:textColor="#468bff"
android:layout_toEndOf="#+id/imageViewIcon"
/>
<TextView
android:id="#+id/author_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/book_title"
android:layout_toRightOf="#+id/imageViewIcon"
android:layout_toEndOf="#+id/imageViewIcon" />
<TextView
android:id="#+id/dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/book_title"
android:layout_toEndOf="#+id/book_title"
android:layout_centerVertical="true"
android:gravity="end"
/>
As you can see in the last TextView I used toRightOf, then gravity end. This causes however to position the last TextView over the 2 lines, so it is not aligned to the right.
Solution can be multiple . Try something like this .
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="vertical">
<ImageView
android:id="#+id/imageViewIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher"
android:layout_alignParentStart="true"
android:paddingEnd="10dp"
android:paddingStart="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_toRightOf="#+id/imageViewIcon"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/dist"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:id="#+id/book_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageViewIcon"
android:textSize="16sp"
android:textColor="#468bff"
android:layout_toEndOf="#+id/imageViewIcon"
/>
<TextView
android:id="#+id/author_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/book_title"
android:layout_toRightOf="#+id/imageViewIcon"
android:layout_toEndOf="#+id/imageViewIcon" />
</LinearLayout>
<TextView
android:id="#+id/dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="end"
/>
</RelativeLayout>
Try the layout below:
<?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="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/iv"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/icon" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:weightSum="100"
android:layout_marginStart="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_1"
android:textSize="20sp"
android:layout_weight="60"
android:text="SOME TITLE"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_2"
android:layout_weight="40"
android:text="Subtitle"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="150m"
android:layout_marginStart="30dp"
android:gravity="center"
android:id="#+id/tv_3"/>
</LinearLayout>
Output:
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>
I am trying the following layout,in that I want to shift image to right but because linear layout is vertically oriented extra spaces are added between textview and image.
I dont want to use Relative layout because I am editing someone else's code and it is just the part of the code.
<LinearLayout
android:id="#+id/llSpouse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/tv_spouse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="SPOUSE"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
<com.ypomumbai.utills.CircularNetworkImageView
android:id="#+id/iv_picture"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="right"
android:layout_alignParentRight="true"
android:src="#android:drawable/ic_menu_info_details" />
<TextView
android:id="#+id/tvSpouseFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="First Name"
android:textStyle="bold" />
<TextView
android:id="#+id/tvSpouseLastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_name"
android:layout_marginLeft="10dp"
android:text="Last Name" />
<TextView
android:id="#+id/tvSpousedesignation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_last_name"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="MD and CEO" />
<TextView
android:id="#+id/tvSpouseCompnayName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_designation"
android:layout_marginLeft="10dp"
android:text="Text" />
</View>
</LinearLayout>
Can anyone help on this.
How to shift image to right without getting extra spaces.
In Vertical linear layout every view will occupy the total row space. So add the margin bottom property to your com.ypomumbai.utills.CircularNetworkImageView with the height of that view.(negative margin will remove the space occupied by this view)
<com.ypomumbai.utills.CircularNetworkImageView
android:id="#+id/iv_picture"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginBottom="-80dp"
android:src="#android:drawable/ic_menu_info_details" />
I don't really understand if you don't want to use a RelativeLayout at all, but I post a sample of code that should work with a relative layout and without breaking the rest :
<LinearLayout
android:id="#+id/llSpouse"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/tv_spouse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="SPOUSE"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvSpouseFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="First Name"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvSpouseLastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_name"
android:layout_marginLeft="10dp"
android:text="Last Name"/>
<TextView
android:id="#+id/tvSpousedesignation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_last_name"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="MD and CEO"/>
<TextView
android:id="#+id/tvSpouseCompnayName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_designation"
android:layout_marginLeft="10dp"
android:text="Text"/>
</LinearLayout>
<ImageView
android:id="#+id/iv_picture"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:src="#android:drawable/ic_menu_info_details"/>
</RelativeLayout>
</LinearLayout>
which renders the following :
EDIT
You can have the same render without RelativeLayout with the following xml :
<LinearLayout
android:id="#+id/llSpouse"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/tv_spouse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="SPOUSE"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvSpouseFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="First Name"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvSpouseLastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Last Name"/>
<TextView
android:id="#+id/tvSpousedesignation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="MD and CEO"/>
<TextView
android:id="#+id/tvSpouseCompnayName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Text"/>
</LinearLayout>
<ImageView
android:id="#+id/iv_picture"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="right"
android:src="#android:drawable/ic_menu_info_details"/>
</LinearLayout>
</LinearLayout>
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
I am unable to get the below shown layout..can anyone let me know how to achieve this layout ?
This is what I have but unable to get the specified layout.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="left"
android:layout_weight="1">
<ImageView
android:id="#+id/someimage"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#88FF0000" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right">
<TextView
android:id="#+id/txtview1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtview2"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="right"
android:layout_below="#id/txtview1"/>
<TextView
android:id="#+id/txtview3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:textColor="#003399"
android:textSize="19sp"
android:textStyle="bold"
android:layout_below="#id/txtview2"/>
</RelativeLayout>
</LinearLayout>
I want to get this as final layout:
You can use a single RelativeLayout
You can remove the unwanted RelativeLayout with black background. (Just to differentiate i added another relative layout with black background)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="15dp"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:src="#drawable/ic_launcher" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:layout_below="#+id/imageView1" >
</RelativeLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="16dp"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="54dp"
android:layout_marginTop="14dp"
android:text="TextView" />
</RelativeLayout>
Edit:
You can also center the text in TextView and use match_parent for the layout width and remove the unwanted realtive layout. Notice the change android:layout_toRightOf="#+id/imageView1" in the below code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView2"
android:layout_toRightOf="#+id/imageView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="15dp"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView3"
android:layout_toRightOf="#+id/imageView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="15dp"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_toRightOf="#+id/imageView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:text="TextView" />
</RelativeLayout>
snap
You need to set the layout_width of all TextViews to fill_parent.
Note that your code should not even compile because the layout_width attribute is mandatory, and you don't specify it for the second TextView, and it also does not have a style attribute where it might be specified.
The below hierarchy can also do what you want:
Linear-Horizontal
Linear-Vertical
imageview
Linear-Horizontal
textview
textview
textview
What about a vertical linear layout where you put the image view in. Also put a horizontal linear layout in, where you place the textviews. Set the vertical height to wrap content and the horizontal to match parent.
Let me know if this works for you
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="left"
android:layout_weight="1">
<ImageView
android:id="#+id/someimage"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#88FF0000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right" >
<TextView
android:id="#+id/txtview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="TextView1"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtview1"
android:focusable="false"
android:gravity="center"
android:text="TextView2" />
<TextView
android:id="#+id/txtview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="19sp"
android:textStyle="bold"
android:gravity="center"
android:text="Textview 3"
android:layout_below="#id/txtview2"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>