I'm trying to make the following xml list:
original list
By the time, I've got this:
my component (which will go inside a list)
Here is my XML component code:
list_item_issue.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<ImageView
android:id="#+id/imageView"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginLeft="#dimen/_5dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="fitXY"
android:src="#drawable/circle_line_shape"
android:tint="#color/colorGray" />
<com.daasuu.bl.BubbleLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="#dimen/_5dp"
android:padding="3dp"
app:bl_arrowDirection="left"
app:bl_arrowHeight="14dp"
app:bl_arrowPosition="10dp"
app:bl_arrowWidth="8dp"
app:bl_cornersRadius="0dp"
app:bl_strokeWidth="0.5dp">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/_5dp"
android:orientation="horizontal">
<TextView
android:id="#+id/parent_list_issue_title_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="3dp"
android:text="Titulo de la incidencia"
android:textSize="12sp"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/parent_list_issue_subtitle_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/parent_list_issue_title_text_view"
android:textColor="#color/grey_semi_transparent"
android:textSize="10sp"
android:text="Subtitulo de la incidencia - Texto de prueba aplicación" />
<ImageButton
android:id="#+id/parent_list_item_expand_arrow"
android:layout_width="30dp"
android:layout_height="25dp"
android:src="#drawable/arrow_drop_down_circle"
android:paddingRight="5dp"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="fitXY"
android:background="#color/white"/>
</RelativeLayout>
</com.daasuu.bl.BubbleLayout>
Here is my circle_line_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="#drawable/ic_circle"
android:gravity="center" />
</item>
</layer-list>
Problem is that I have no idea of how to make those circles + vertical lines aligned with the BubbleLayout like you can see on the original list image.
¿Shall I change my layout structure?
Thank you very much!
Use a RelativeLayout, not a Linear. Make the image view match_parent height. Make the bubble layout_toEndOf the image view. Make the relative_layout itself wrap_content. This will make the relative layout the hight of the bubble layout, and the image the height of the relative layout.
Related
Is there an easy way to place a TextView on top of ImageView?
My code:
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="#drawable/finaloval"
android:elevation="10dp"
android:layout_centerHorizontal="true"
android:id="#+id/greencircleId"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:id="#+id/textView"
android:textSize="40sp"
android:textColor="#color/colorAccent" />
Example Image
The green circle would be my #drawable/finaloval. And the %100 organic would be the TextView.
<TextView android:id="#+id/tv_versionstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:drawableBottom="#drawable/icon_new"
android:text="text"
android:textColor="#363636"
android:textSize="20sp" />
drawableBottom is also a choise for you
Please try to set the background for the layout and place your textviews inside that , i have coded it as per the image you shared in it example
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:background="#drawable/finaloval">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100% natural"
android:layout_marginTop="23dp"
android:id="#+id/natural"
android:textSize="20sp"
android:textColor="#color/colorAccent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="organic"
android:layout_marginTop="23dp"
android:layout_below="#id/"
android:id="#+id/natural"
android:textSize="40sp"
android:textColor="#color/colorAccent" />
</RelativeLayout>
try this xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="#drawable/finaloval"
android:layout_gravity="center"
android:elevation="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:textSize="40sp"
android:layout_gravity="center"
android:textColor="#color/text_black" />
</FrameLayout>
Just use a LinearLayout as root and re-sequence your views from top to bottom, meaning in your case should be TextView then ImageView.
Edited based on comment
To do overlap of views, you can use RelativeLayout or FrameLayout as suggested by others.
Try this:
<?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="fill_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:layout_marginTop="23dp"
android:id="#+id/textView"
android:textSize="40sp"
android:textColor="#color/colorAccent" />
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="#drawable/finaloval"
android:elevation="10dp"
android:id="#+id/greencircleId"/>
</RelativeLayout>
Think this is the simplest way of doing. Hope this helps
Try to set the imageview as the background of the textview.
Do you want to put some words upon a image or a sharp drawable?
I'll use a shape drawable to make an example.
Now I have a shape like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<size
android:height="100dp"
android:width="100dp"
/>
<solid
android:color="#66ccff"
/>
</shape>
Then set it as the background of a textview in a layout xml.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/circle"
android:text="Hello World!"
/>
That looks like it. It's a 100dp*100dp one.
100*100
And try to modify the width and height of the textview.
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#drawable/circle"
android:text="Hello World!"
/>
Now it looks like this. A Lot Larger.
200*200
So the conclusion is:
Change the size of drawable and use wrap_content in the layout xml.
Change "layout_width" and "layout_height" in the layout xml.
But if you want to use the smaller one or the lager one, maybe you should add some control codes in the control java file.
(Sorry I'm not in a English-spoken country so maybe my words is not clear enough)
I'm sorry that I didn't obverse the rules before answer (cuz it's my first answer).
I want to make a shopping cart image, with a little indicator at the top-right corner to show how many products were selected/ordered.
The thing is, I can't place it in the top right corner, only the left one (default) or center.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/shoppingCartIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_cart" />
<ImageView
android:id="#+id/indicatorIcon"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_gravity="top|right"
android:src="#0066ff" />
</RelativeLayout>
By using FrameLayout you can give it with some padding & margin
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/shoppingCartIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_cart" />
<ImageView
android:id="#+id/indicatorIcon"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_gravity="top|right"
android:src="#0066ff" />
</FrameLayout>
UPDATE
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/shoppingCartIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_cart" />
<TextView
android:id="#+id/indicatorIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:layout_marginLeft="25dp"
android:background="#drawable/circle_shape"
android:text="5"
android:textSize="24sp" />
</FrameLayout>
You can create shape as per your wish
res/drawable/circle_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#0066ff"></solid>
</shape>
Apart from this i would suggest you other third library which is very nice for displaying this type of badge or highlighted view
https://github.com/jgilfelt/android-viewbadger
https://github.com/mikepenz/Android-ActionItemBadge
you can add this code to your ImageView tag.
android:layout_marginLeft="90dp"
It will make the ImageView go right marginLeft gives a blank depends on the size you want. You can change the size however you want.
The parent is a RelativeLayout so try to use the properties :
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
on your "#+id/indicatorIcon".
Hope it helps.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/shoppingCartIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_cart" />
<ImageView
android:id="#+id/indicatorIcon"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="#0066ff" />
</RelativeLayout>
I customized the ActionBar by inflating a custom view.
and my custom action bar XML layout is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal"
android:background="#drawable/actionbar_bg" >
<TextView
android:id="#+id/ab_main_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:gravity="right|center_vertical"
android:text="heaer_text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
<ImageView
android:id="#+id/ab_main_img0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:clickable="true"
android:src="#drawable/ab_main_img_layer_list" />
</RelativeLayout>
but I don't know why there is an unwanted left padding for my ImageView at run time!!! like image below:
anybody know?
It seems that when you use "wrap_content" or "match_parent" in your ImageView (not TextView) on your custom action bar xml layout, you will have padding in your action bar, otherwise you don't have.
So please try changing your xml as below: setting fixed size to the ImageView (and you can also add some margin_left for a better look).
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal"
android:background="#drawable/actionbar_bg" >
<TextView
android:id="#+id/ab_main_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:gravity="right|center_vertical"
android:text="heaer_text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
<ImageView
android:id="#+id/ab_main_img0"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:clickable="true"
android:src="#drawable/ab_main_img_layer_list" />
</RelativeLayout>
EDIT: Just edited my answer for a more accurate explanation of the issue :). Hope it will help others as well.
You should try this
android:layout_marginLeft="5dp"
inside ImageView
<ImageView
android:id="#+id/ab_main_img0"
android:layout_width="50px"
android:layout_height="50px"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:clickable="true"
android:layout_marginLeft="5dp"
android:src="#drawable/ab_main_img_layer_list" />
I'm currently trying to create a list item similar to the one in the official design guidelines. Still missing is the vertical divider next to the button/image on the right side of each item. Most people seem to use a separate View with a fixed width for that, but the height doesn't scale in my case. It's only shown when I set a fixed height for the divider itself or the parent RelativeLayout. Is it possible to let it scale automatically?
My layout XML for the list item looks like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/sensors_list_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="10dp" />
<TextView
android:id="#+id/sensors_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_toRightOf="#id/sensors_list_img"
android:paddingTop="5dp" />
<TextView
android:id="#+id/sensors_list_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_below="#id/sensors_list_name"
android:layout_toRightOf="#id/sensors_list_img"
android:paddingBottom="5dp" />
<ImageView
android:id="#+id/sensors_list_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:padding="10dp"
android:src="#drawable/ic_angle_right" />
<View
android:id="#+id/sensors_list_divider"
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_toLeftOf="#id/sensors_list_details"
android:background="#ff0000" />
</RelativeLayout>
Try to assign an height related to the image like:
android:alignTop="#id/myimage"
android:alignBottom="#id/myimage"
otherwise you can create a xml drawable and use it with an ImageView :
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="1dp" android:color="#000000"/>
</shape>
Update
Remember android:shape="line" doesn't work without stroke
Let's go with a LinearLayout as a parent:
<?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">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/sensors_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="5dp" />
<TextView
android:id="#+id/sensors_list_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:paddingBottom="5dp" />
</LinearLayout>
<View
android:id="#+id/sensors_list_divider"
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#ff0000" />
<ImageView
android:id="#+id/sensors_list_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="#drawable/ic_angle_right" />
</LinearLayout>
Check this
listView.setDividerHeight(1);
i want to design a layout for my app as shown below in image
but im getting problem which is that the properties im applying for relative layout are not going right as in below my xml code there is horizontal ruler image having centerInParent property and a verticle ruler image also having property of centerInParent by doing this the both rulers come to accurate place but when i put a child above the horizontal ruler or a child toLeftOf verticle ruler they dont appear as the graphical view of xml file shows the reason that although by applying centerInParent the both rulers come to center but their reference remains at edges thats why by using layout_above or layout_toLeftOf the childs go outside of layout
My xml code
<?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:background="#FFFFFF"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/title"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/icon_img"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dip"
android:layout_marginTop="2.5dip"
android:src="#drawable/smicon"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_toRightOf="#id/icon_img"
android:layout_marginTop="3dip"
android:text="Welcome To JEM"
android:textStyle="bold"
android:id="#+id/wcm_id"
android:textSize="18dip"
android:textColor="#FFFFFF"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/wcm_id"
android:layout_alignParentRight="true"
android:layout_marginRight="5dip"
android:text="APPS BY SAM"
android:id="#+id/app_by"
android:textSize="16dip"
android:textColor="#FFFFFF"
/>
</RelativeLayout>
<!-- This relative layout which is showing the main cross and icon around it -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/center_hr"
android:layout_centerInParent="true"
android:src="#drawable/horizontal"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/center_vr"
android:layout_centerInParent="true"
android:src="#drawable/verticle"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/center_hr"
android:layout_toLeftOf="#id/center_vr"
android:id="#+id/getuser"
android:src="#drawable/adduser"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/center_hr"
android:layout_toRightOf="#id/center_vr"
android:id="#+id/set"
android:src="#drawable/set"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/center_hr"
android:layout_toLeftOf="#id/center_vr"
android:id="#+id/get"
android:src="#drawable/get"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/center_hr"
android:layout_toRightOf="#id/center_vr"
android:id="#+id/ico"
android:src="#drawable/icon"
/>
</RelativeLayout>
</LinearLayout>
so guys please tell me how can i achive this main cross and icon to lef,right and above,below it as shown in image
Try this..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="#+id/vertical_ruler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/imageView1"/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/vertical_ruler"
/>
<ImageView
android:id="#+id/horizontal_ruler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView1"/>
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/horizontal_ruler"/>
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/vertical_ruler"
android:layout_below="#id/horizontal_ruler"
/>
May be it helpful for you..
You could use a TableLayout embedded in a RelativeLayout. The RelativeLayout can be used to center the TableLayout on the screen and in the TableLayout you can add your pictures/buttons and state how many rows and colums you want the TableLayout to have.