mardi 26 mai 2015

Custom TextView features using android:background tag more than once

I have a problem with the android:background tag, which I am only able to use once, while I need more than once feature for my TextViews. More details below:

I have 3 TextView:

<LinearLayout android:id="@+id/info" android:layout_marginTop="68dp"
        android:layout_width="wrap_content" android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal">

        <TextView android:id="@+id/tour1"
            android:paddingLeft="10dp" android:paddingRight="10dp"
            android:paddingTop="8dp" android:paddingBottom="8dp"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/back"
            android:gravity="center"
            android:text="Tour \n disponibili  \n 21"/>

        <TextView android:id="@+id/tour2" android:layout_toRightOf="@+id/tour1"
            android:paddingLeft="10dp" android:paddingRight="10dp"
            android:paddingTop="8dp" android:paddingBottom="8dp"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/back"
            android:gravity="center"
            android:text="Tour \n prenotabili  \n 16"
            android:layout_marginLeft="16dp"/>

        <TextView android:id="@+id/tour3" android:layout_toRightOf="@+id/tour2"
            android:paddingLeft="10dp" android:paddingRight="10dp"
            android:paddingTop="8dp" android:paddingBottom="8dp"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/back"
            android:gravity="center"
            android:text="Tour \n preferiti  \n 3"
            android:layout_marginLeft="16dp"/>
    </LinearLayout>

shown here:

enter image description here

The TextView border is obtained with this file, back.xml, included in res/drawable folder:

<shape xmlns:android="http://ift.tt/nIICcg"   
    android:shape="rectangle" >
    <!--<solid android:color="#ffffff" />-->
    <stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>

Since I am already using the background tag to input the back.xml file and create a rectangular border for the TextViews, I don't know how to use it for my other needs, which are:

  • get a border for the TextView WITH also round corners
  • get an icon as background of the TextView as shown here: here

As far as I know I can only do this with the tag background, which is already used to get the back.xml drawable.

How can I fulfill my needs?

Aucun commentaire:

Enregistrer un commentaire