J'essaie d'obtenir que ce code fonctionne pour mon application Android, mais je ne peux pas obtenir mon rectangle et je ne sais pas comment mettre du texte dans ce rectangle.
Ceci est mon fichier shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp"
android:color="#ababab"
/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"
/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>
C'est mon fragment_task.xml
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape"
android:orientation="vertical"
android:layout_marginRight="10dp"
android:id="@+id/linearLayout">
</LinearLayout>
</GridLayout>
Réponses:
2 pour la réponse № 1La mise en page linéaire est définie pour envelopper le contenu et arien à l'intérieur. Ce que vous voulez probablement faire est de placer la vue de texte dans la disposition linéaire. Vous pouvez donc la déplacer simplement, ou tout simplement supprimer la disposition linéaire et définir l'arrière-plan de la vue de texte sur votre dessin.