How can I achieve this listview row layout in XML? - android

I can't seem to get the date positioned appropriately in the layout. I am trying to achieve something like this:
I need to have the date appear below the first line of the notifications. I'm just not sure how to incorporate a vertical linear layout here properly.
Here's the XML code I have so far:
<?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"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/user_avatar_notification"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp" />
<TextView
android:id="#+id/post_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="username"
android:textSize="16dp" />
<TextView
android:id="#+id/post_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="mentioned you in a"
android:textColor="#color/comment_like_grey" />
<TextView
android:id="#+id/notification_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="not_type"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date of notification"
android:textColor="#color/comment_like_grey"
/>
</LinearLayout>

Try something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/user_avatar_notification"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/post_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="username"
android:textSize="16dp" />
<TextView
android:id="#+id/post_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="mentioned you in a"
android:textColor="#color/comment_like_grey"/>
<TextView
android:id="#+id/notification_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="not_type" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date of notification"
android:textColor="#color/comment_like_grey"/>
</LinearLayout>
</LinearLayout>

Related

Binding of two TextViews on vertical

There is a RelativeLayout with a nested LinearLayout that contains two TextViews positioned horizontally relative to each other. This is DiscountAmount and AmountWithDiscount.
I need to keep the DiscountAmount and AmountWithDiscount always at the same level vertically, for this I put the android property in LinearLayout: android:layout_below = "# + id / textViewRowQuantity". But if the Name is too long and takes three lines, then it will go to DiscountAmount. If Name takes no more than 2 lines, then all is well.
Tell me, please, how can I solve this problem?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayoutSaleListRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="#+id/imageViewRemoveRowSale"
android:layout_width="#dimen/size_30px"
android:layout_height="#dimen/size_30px"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:src="#drawable/ic_action_remove"/>
<RelativeLayout
android:id="#+id/relativeLayoutIncQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_toRightOf="#+id/imageViewRemoveRowSale"
android:layout_toLeftOf="#+id/imageViewEditRowSale"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewRowPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRowPrice"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/textViewRowPrice"
android:text="TextView" />
<LinearLayout
android:id="#+id/layoutDiscount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRowQuantity"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewRowDiscountAmount"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowAmountWithDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:text="TextView" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="#+id/imageViewEditRowSale"
android:layout_width="#dimen/size_45px"
android:layout_height="#dimen/size_45px"
android:layout_marginTop="5dp"
android:layout_alignParentRight="true"
android:src="#drawable/ic_action_edit" />
Add result:
Implemented through ConstraintLayout. Thanks to all.
You can limit the number of lines in the TextView to 2 by adding this lines:
android:ellipsize="end"
android:lines="2"
End ellipsize end means if the text is so long then it will be replaced with three dots ...
if you want to show AmountWithDiscount is below to discount then change liner layout orientation like below .
android:orientation="vertical"
Try this :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayoutSaleListRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="#+id/imageViewRemoveRowSale"
android:layout_width="#dimen/size_30px"
android:layout_height="#dimen/size_30px"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:src="#drawable/ic_action_remove"/>
<RelativeLayout
android:id="#+id/relativeLayoutIncQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_toRightOf="#+id/imageViewRemoveRowSale"
android:layout_toLeftOf="#+id/imageViewEditRowSale"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewRowPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRowPrice"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/textViewRowPrice"
android:text="text"
android:minLines="2"/>
<LinearLayout
android:id="#+id/layoutDiscount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRowName"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewRowDiscountAmount"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowAmountWithDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:text="TextView" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="#+id/imageViewEditRowSale"
android:layout_width="#dimen/size_45px"
android:layout_height="#dimen/size_45px"
android:layout_marginTop="5dp"
android:layout_alignParentRight="true"
android:src="#drawable/ic_action_edit" />
</RelativeLayout>
Hope this helps
make some change in liner layout..
<LinearLayout
android:id="#+id/layoutDiscount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRowQuantity"
android:orientation="horizontal"
android:weightSum="1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3">
<TextView
android:id="#+id/textViewRowDiscountAmount"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:singleLine="true"
android:text="TextViewsdfsdfdsgfd" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7">
<TextView
android:id="#+id/textViewRowAmountWithDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:singleLine="true"
android:layout_marginRight="5dp"
android:text="textview" />
</LinearLayout>
</LinearLayout>
You can try out this below code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayoutSaleListRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="#+id/imageViewRemoveRowSale"
android:layout_width="#dimen/size_30px"
android:layout_height="#dimen/size_30px"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:src="#drawable/ic_action_remove"/>
<RelativeLayout
android:id="#+id/relativeLayoutIncQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_toRightOf="#+id/imageViewRemoveRowSale"
android:layout_toLeftOf="#+id/imageViewEditRowSale"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rr_layout">
<TextView
android:id="#+id/textViewRowPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRowPrice"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/textViewRowPrice"
android:text="TextView" />
</RelativeLayout>
<LinearLayout
android:id="#+id/layoutDiscount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rr_layout"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewRowDiscountAmount"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textViewRowAmountWithDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:text="TextView" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="#+id/imageViewEditRowSale"
android:layout_width="#dimen/size_45px"
android:layout_height="#dimen/size_45px"
android:layout_marginTop="5dp"
android:layout_alignParentRight="true"
android:src="#drawable/ic_action_edit" /></RelativeLayout>

Difficulty in aligning child to the mostleft and mostright in-between another child

I want two images to be displayed on left and right and a textview in between them just at small distance to the left image but I couldn't get it done.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/image_of_services"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/name_of_services"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:text="adasdsad"
android:layout_weight="8"
android:textSize="20sp" />
<ImageView
android:id="#+id/image_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="2"
android:src="#drawable/ic_menu_camera" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="10"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="#+id/image_of_services"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="2"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/name_of_services"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="adasdsad"
android:layout_weight="6"
android:textSize="20sp" />
<ImageView
android:id="#+id/image_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="2"
android:src="#drawable/ic_menu_camera" />
</LinearLayout>`
<?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="70dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/image_of_services"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/name_of_services"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_weight="1"
android:text="adasdsad"
android:textSize="20sp" />
<ImageView
android:id="#+id/image_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:src="#drawable/ic_menu_gallery" />
</LinearLayout>
i have edited the code and it worked perfectly as i desired

How to achieve this xml?

I want to achieve like the image below
And I tried, but it is not my desired result.
Below is my xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip">
<LinearLayout android:id="#+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip">
<ImageView
android:id="#+id/photo"
android:layout_width="70dp"
android:layout_height="70dp"
android:scaleType="centerCrop"
android:layout_gravity="center"/>
</LinearLayout>
<TextView
android:id="#+id/ListDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/input_register"
android:text="Date"
android:layout_marginLeft="150dp"
android:layout_alignTop="#+id/thumbnail"
android:layout_toRightOf="#+id/thumbnail" />
<TextView
android:id="#+id/ListDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="20sp"
android:text="Description"
android:ellipsize="end"
android:textStyle="bold"
android:layout_below="#id/ListDate"
android:layout_toRightOf="#+id/thumbnail" />
<TextView
android:id="#+id/ListAmount"
android:text="Amount"
android:layout_marginTop="40dp"
android:layout_marginLeft="166dp"
android:textSize="20sp"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_toRightOf="#+id/thumbnail"
android:textColor="#color/violetred" />
</RelativeLayout>
How can I write the ... beside the Amount TextView same like the first image I post ? Any help is much appreciated.
You can have only one layout which will solve your problem nesting is not a good idea.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="#000"
android:layout_gravity="center"
android:textSize="?android:actionBarItemBackground"
android:textStyle="bold"
android:text="8 hours # $80.00/hour"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="2014-05-08"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_horizontal_margin"
android:textStyle="bold"
android:layout_gravity="end"
android:textColor="#000"
android:textSize="?android:actionBarItemBackground"
android:text="$640.00"/>
</FrameLayout>
you can achieve your requirement with this xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#d8d8d8" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="85dp"
android:layout_height="85dp"
android:background="#c8c8c8"
android:src="#drawable/ic_launcher" >
</ImageView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageView1"
android:text="TextView"
android:textColor="#000000" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dp"
android:layout_marginTop="20dp"
android:padding="2dp"
android:text="2014-05-08"
android:textColor="#000000" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView2"
android:layout_marginRight="6dp"
android:layout_marginTop="20dp"
android:padding="2dp"
android:text="$600"
android:textColor="#000000"
android:textStyle="bold" />
</RelativeLayout>
hope this helps you.exact xml of you want to achieve.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip">
<ImageView
android:id="#+id/photo"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:padding="3dp"
android:scaleType="centerCrop"
android:layout_gravity="center"/>
<TextView
android:id="#+id/ListDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/right_container"
android:singleLine="true"
android:textSize="20sp"
android:text="Description"
android:ellipsize="end"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/photo" />
<LinearLayout
android:id="#+id/right_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="vertical">
<TextView
android:id="#+id/ListDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#color/input_register"
android:text="12-11-2017"
android:layout_marginRight="10dp"/>
<TextView
android:id="#+id/ListAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="777$"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:textSize="20sp"
android:textColor="#color/violetred" />
</LinearLayout>
Use constraint layout for best performance. If not, use horizontal linear layout, with weight on the center one.
<?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="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="5dip">
<ImageView
android:id="#+id/photo"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#color/black"
android:scaleType="centerCrop" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center_vertical"
android:lines="1"
android:text="Buy drinks fvbfvfvfvasdasdasdfvfvvfvf" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="1014-05-08" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="$6969"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.5"
android:ellipsize="end"
android:maxLines="1"
android:text="ASASJHGHHBHHJHJNKMKIKMKMKMKMKKNIKNIJ" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2016-01-11" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="$640"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
try this
<?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="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:padding="5dip">
<LinearLayout android:id="#+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:weightSum=".20"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip">
<ImageView
android:id="#+id/photo"
android:layout_width="70dp"
android:layout_height="70dp"
android:scaleType="centerCrop"
android:layout_gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum=".80"
android:layout_alignRight="#+id/thumbnail"
android:layout_alignParentRight="true"
android:orientation="vertical">
<TextView
android:id="#+id/ListDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginRight="10dp"
android:textColor="#color/input_register"
android:text="Date"
/>
<TextView
android:id="#+id/ListDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_marginRight="10dp"
android:textSize="20sp"
android:text="DescriptionDescriptionDescriptionDescription"
android:ellipsize="end"
android:textStyle="bold"
/>
<TextView
android:id="#+id/ListAmount"
android:text="Amount"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="end"
android:layout_marginRight="10dp"
android:layout_toRightOf="#+id/thumbnail"
android:textColor="#color/violetred" />
</LinearLayout>
</LinearLayout>

Actionbar overlapping Scrollbar inside fragment

I have a scrollview as the root view of a fragment. It's child is a vertical linear layout with 4 elements. The first element is an image. The issue is that the image is getting cut and I can't seem to scroll upwards. This issue is only in landscape mode. Following is my xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:weightSum="4"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo_dark"
android:id="#+id/imageView2"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:layout_gravity="center"
android:id="#+id/linearLayout3">
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/student"
android:layout_gravity="center" />
<AutoCompleteTextView
android:id="#+id/new_form_student"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:textColor="#color/colorPrimary"
android:textColorHint="#fff"
android:padding="10dp" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/person"
android:layout_gravity="center" />
<AutoCompleteTextView
android:id="#+id/new_form_person"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:textColor="#color/colorPrimary"
android:textColorHint="#fff"
android:padding="10dp" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/reason"
android:layout_gravity="center" />
<AutoCompleteTextView
android:id="#+id/new_form_reason"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:textColor="#color/colorPrimary"
android:textColorHint="#fff"
android:padding="10dp" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/check"
android:layout_gravity="center" />
<AutoCompleteTextView
android:id="#+id/new_form_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:textColor="#color/colorPrimary"
android:textColorHint="#fff"
android:padding="10dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/submit"
android:id="#+id/new_form_submit"
android:padding="10dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/cancel"
android:id="#+id/new_form_cancel"
android:padding="10dp"/>
</LinearLayout>
And this is the screenshot of the issue:
Thanks,
Found it here:
Remove layout_gravity attribute from the Linear Layout that is directly placed inside scrollView, in your case,
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!-- android:layout_gravity="center" -->
android:weightSum="4"
android:orientation="vertical">
instead of:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:weightSum="4"
android:orientation="vertical">

How can i implement this layout?

I have a layout that has 3 buttons. And I want to locate two textviews to each imageview. How can i implement this layout? AbsoluteLayout is enough for my needs?
Here is my layout part.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_gravity="center_horizontal"
android:weightSum="2" >
<ImageView
android:id="#+id/btn1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/gray" />
<ImageView
android:id="#+id/btn2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/gray" />
<ImageView
android:id="#+id/btn3"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/gray" />
</LinearLayout>
I want to implement this layout. Boxes are imageview.
a busy cat http://img824.imageshack.us/img824/2385/layoutrq.jpg
Using Linear Layout you can do like this.
<?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:weightSum="3"
android:background="#F0F0F0" >
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="TextView" />
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="TextView" />
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
Use RelativeLayout instead of ImageView :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#000">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:text="TextView2" />
</RelativeLayout>
I would recommend to create a separate layout and class for it for reusing.
use Button instead of ImageView.
Use the Button instead of ImageView, You probably want a custom button background?
Use this:
<ImageButton
android:id="#+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/album_icon"
android:background="#drawable/round_button" />
Or this to still use the image file:
ImageView iv = (ImageView)findViewById(R.id.ImageView01);
iv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
Is this what you need?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:gravity="center"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/btn1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:layout_alignParentLeft="true"
android:background="#drawable/gray"
android:orientation="vertical">
<TextView
android:id="#+id/txt1"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Label 1" />
<TextView
android:id="#+id/txt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:text="Label 2" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/btn2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:layout_toRightOf="#id/btn1"
android:background="#drawable/gray"
android:orientation="vertical">
<TextView
android:id="#+id/txt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:text="Label 3" />
<TextView
android:id="#+id/txt4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:text="Label 4" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/btn3"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:layout_toRightOf="#id/btn2"
android:background="#drawable/gray"
android:orientation="vertical">
<TextView
android:id="#+id/txt5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:text="Label 5" />
<TextView
android:id="#+id/txt6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:text="Label 6" />
</RelativeLayout>
</RelativeLayout>
Edit: Check now. You can set the background of the relativeLayouts to whatever you wanted in the imageviews and set a clicklistener so they act like buttons.

Categories

Resources