0
I’m trying to make the items on my list look like figure 2, but they only look like figure 1. I did a lot of research on it, but I found very little about it (I don’t really know what to search for).
Follow my XML file:
<?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:orientation="horizontal"
android:id="@+id/lista_linhas"
android:padding="5dp">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/border_radius"
android:layout_margin="0dp"
android:padding="0dp"
android:id="@+id/teste"
android:layout_centerInParent="true"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:padding="0dp"
android:id="@+id/circulo">
<TextView
android:layout_width="5dp"
android:layout_height="48dp"
android:layout_margin="0dp"
android:padding="0dp"
android:layout_alignParentLeft="true"
android:id="@+id/cor_esquerda" />
<TextView
android:layout_width="38dp"
android:layout_height="48dp"
android:layout_margin="0dp"
android:padding="0dp"
android:gravity="center"
android:textAlignment="center"
android:layout_centerInParent="true"
android:textColor="@color/preto"
android:id="@+id/numero" />
<TextView
android:layout_width="5dp"
android:layout_height="48dp"
android:layout_margin="0dp"
android:padding="0dp"
android:layout_alignParentRight="true"
android:id="@+id/cor_direita" />
</RelativeLayout>
</RelativeLayout>
border-Radius.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ffffff" />
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:radius="50dp" />
</shape>
It could include the
border_radius.xml
? I would like to test this layout to see how to get it right. It came to think about doing withCanvas
?– Wakim
I edited the question and included the xml of the rounded border. I don’t know Canvas, I can do with it?
– Mukotoshi
It depends on the type of interaction that the
View
will have, because with theCanvas
you have access only to the drawing primitives (draw rectangle, square, lines, circles, arcs, write text and etc), it is more difficult to work with click events and etc. If there is no alternative, think you have, the solution is to useCanvas
.– Wakim
These drawings work as a kind of icons in a Listview, I will need to work with their click. Using Canvas would make this MUCH more difficult?
– Mukotoshi
If you click on
View
whole, not in parts, just implement correctly the methodonMeasure
(where you say the dimensions ofView
with certain restrictions based onlayout_width
andlayout_height
who gave them), have a look at: http://developer.android.com/training/custom-views/index.html, http://www.jayway.com/2012/12/creating-custom-android-views-part-4-measuring-and-how-to-forca-view-to-be-square/ and http://blog.denevell.org/android-custom-viewsonlayout-onmeasure.html.– Wakim
Sometimes make a
Custom View
is much more efficient, because to make a simple drawing you had to use 6Views
and it’s not good yet. Imagine in aListView
multi-element?– Wakim
Okay, thank you. I’ll take a look at these links.
– Mukotoshi
If I can solve the problem I put the solution here.
– Wakim