-6

Das ist mein Layout XML:Warum erscheint mein TextView ohne Grenzen in einem LinearLayout?

Und

<LinearLayout android:layout_height="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello World!" /> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="2dp" 
     android:background="@drawable/border" /> 

    <TextView android:text="ahahah 2!" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/border" 
     xmlns:android="http://schemas.android.com/apk/res/android" /> 

</LinearLayout> 

dies die Grenze Definition lautet:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 
    <solid android:color="@android:color/white" /> 
    <stroke android:width="1dip" android:color="#4fa5d5"/> 
</shape> 

Dies ist eine horizontale Linie zwischen den TextView s erscheinen lässt, aber ich bin eine Grenze erwartet um den Text der TextView s selbst. Wie mache ich das möglich?

+0

nur nützlich sein können 'wrap_content' für die Höhe Attribut an Ihrem 2. TextView – convexHull

+0

entfernen Sie dies aus der Ansicht: Android: Hintergrund = "@ Drawable/Border" und bieten Farbe dafür, es wird funktionieren. –

Antwort

0

Einfach in Text View selbst definieren.

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/border" 
    android:text="Hello World!" /> 

Ändern Sie Ihr XML-Code

<?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"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="10dp" 
     android:background="@drawable/border" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp" 
     android:paddingTop="5dp" 
     android:paddingBottom="5dp" 
     android:text="Hello World!" 
     android:textSize="22sp" /> 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="10dp" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp" 
     android:paddingTop="5dp" 
     android:paddingBottom="5dp" 
     android:background="@drawable/border" 
     android:text="Hello World!" 
     android:textSize="22sp" /> 


</LinearLayout> 
0

Versuchen Sie, diese

<?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:padding="5dp" 
android:orientation="vertical"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello World!" /> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="2dp" 
    android:background="@drawable/border" /> 

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/border" 
    android:text="ahahah 2!" /> 

</LinearLayout> 
0

Ihr Layout-Datei ändern:

<?xml version="1.0" encoding="utf-8"?> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello World!" /> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="2dp" 
    android:background="@drawable/border" /> 

<TextView android:text="ahahah 2!" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dp" 
    android:background="@drawable/border" 
    xmlns:android="http://schemas.android.com/apk/res/android" /> 

0
 <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/border" 
     android:text="desired text" 
     android:layout_margin="5dp"/> 

Versuchen diesem Hintergrund xml

  <?xml version="1.0" encoding="utf-8"?> 
      <shape 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:shape="rectangle"> 

      <stroke android:color="@color/colorPrimary" 
      android:width="1dp"/> 
      <solid android:color="@color/colorPrimary"/> 
      <corners android:radius="5dp"/> 
     </shape> 

Ihre Textview haben mit Marge Design nach.

+0

Bitte ausführliche Antwort. –

0
<?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"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="10dp" 
     android:background="@drawable/border" 
     android:text="Hello World!" 
     android:textSize="22sp" /> 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="10dp" 
     android:background="@drawable/border" 
     android:text="Hello World!" 
     android:textSize="22sp" /> 


</LinearLayout> 
0

wenn Sie padding auf Textview und entfernen Ansicht zwischen Textviews anwenden, die fein arbeiten, versuchen Sie diesen Code .... es funktioniert

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/border" 
    android:layout_marginTop="20dp" 
    android:padding="5dp" 
    android:layout_gravity="center" 
    android:gravity="center" 
    android:text="ahahah 2!" /> 
Verwandte Themen