2017-12-19 3 views
-1
<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="2"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:textSize="24sp" 
      android:text="Name." 
      android:textColor="#000" 
      android:textStyle="bold" 
      android:background="#c91799c9" 
      android:layout_height="wrap_content" /> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:textSize="17sp" 
      android:paddingLeft="8dp" 
      android:text="Paragraph" 
      android:textColor="#000" 
      android:textStyle="bold" 
      android:background="#3f1799c9" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

In dem angegebenen Code habe ich 2 Textansichten in einer horizontalen Ansicht. Ich mag, dass, wenn der Text von einem Textview in einer anderen Linie geht, sollte der anderen Textview Raum auch nach einem erstenErweitern Sie einen Textansichtsbereich in Bezug auf einen anderen

erhöht wird

Wie in gegebenen Bild Absatz in 3-4 Zeilen sein kann, aber ich wollen Name des Textview sollte vertikal erweitert werden diese

+1

meine Antwort überprüfen. –

+0

Mögliches Duplikat von [wie width eingestellt wird, das einem anderen Widget auf Android entspricht] (https://stackoverflow.com/questions/9977721/how-to-set-width-which-is-equal-to-another-widget -on-android) –

Antwort

0

Versuchen:

Gib Höhe match_parent

enter image description here

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="2"> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#c91799c9" 
     android:text="Name." 
     android:textColor="#000" 
     android:textSize="24sp" 
     android:textStyle="bold" /> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#3f1799c9" 
     android:paddingLeft="8dp" 
     android:text="paragraph" 
     android:textColor="#000" 
     android:textSize="17sp" 
     android:textStyle="bold" /> 

</LinearLayout> 

Wenn Sie den Text in der Mitte wollen Sie android:gravity="center_vertical" in beiden Textview hinzufügen können.

+1

Wenn dies Ihr Problem löst, dann bitte upvote die Antwort :) –

2

Versuchen Sie, diese

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="2"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:textSize="24sp" 
      android:text="Name." 
      android:textColor="#000" 
      android:textStyle="bold" 
      android:background="#c91799c9" 
      android:layout_height="match_parent" /> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:textSize="17sp" 
      android:paddingLeft="8dp" 
      android:text="Paragraph" 
      android:textColor="#000" 
      android:textStyle="bold" 
      android:background="#3f1799c9" 
      android:layout_height="match_parent" /> 

    </LinearLayout> 

</LinearLayout> 

Ausgabe

enter image description here

1

die Sie interessieren, setzen Sie android:layout_height="match_parent" in beiden textView auch können Sie Textsize gleiche in beiden textViewandroid:textSize="24sp"

eingestellt
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:weightSum="2"> 

<TextView 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:background="#c91799c9" 
    android:text="Name." 
    android:textColor="#000" 
    android:textSize="24sp" 
    android:textStyle="bold" /> 

<TextView 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:background="#3f1799c9" 
    android:paddingLeft="8dp" 
    android:text="Paragraph" 
    android:textColor="#000" 
    android:textSize="17sp" 
    android:textStyle="bold" /> 

</LinearLayout> 
0

Geben Sie dem ersten TextView.ie einen Schwerpunkt in der Mitte, fügen Sie den ersten TextView 'Name' unterhalb des Codes hinzu.

android:layout_gravity="center" 

Und auch die Höhe von beiden TextView zu match_parent ändern.

android:layout_height="match_parent" 
-1
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="2" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:textSize="24sp" 
     android:text="Name" 
     android:textColor="#000" 
     android:textStyle="bold" 
     android:gravity="center" 
     android:background="#c91799c9" 
     android:layout_height="match_parent" /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:textSize="17sp" 
     android:paddingLeft="8dp" 
     android:text="Paragraph" 
     android:gravity="center" 
     android:textColor="#000" 
     android:textStyle="bold" 
     android:background="#3f1799c9" 
     android:layout_height="match_parent" /> 

</LinearLayout> 
Verwandte Themen