2016-08-14 70 views
-1

在ANDROID工作室中運行下面的代碼並沒有給我想要的結果:請幫忙嗎?我希望3個TextView在設備的屏幕中垂直分佈。線性佈局中的等距垂直間距不起作用

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

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:text="Debanshu" 
    android:textSize="24sp"/> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:text="Chakraborty" 
    android:textSize="24sp" 
    android:layout_weight="1" /> 

<TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:text="Voltas" 
     android:textSize="24sp" 
     android:layout_weight="1"/> 

</LinearLayout> 
+0

。謝謝大家。現在工作。剛開始學習。 – user185995

+0

使用屏幕截圖會更容易出錯。 –

回答

0

我相信你想這個(只是爲了好玩加入重力):

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

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:text="Debanshu" 
    android:gravity="center" 
    android:textSize="24sp"/> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:text="Chakraborty" 
    android:textSize="24sp" 
    android:gravity="center" 
    android:layout_weight="1" /> 

<TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:text="Voltas" 
     android:textSize="24sp" 
     android:gravity="center" 
     android:layout_weight="1"/> 

</LinearLayout> 
0

正如你LinearLayout高度等於wrap_content其工作,但由於身高包裝視圖你沒有得到需要的視圖

試試下面讓LinearLayout高度等於match_parent

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

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="Debanshu" 
     android:textSize="24sp"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:text="Chakraborty" 
     android:textSize="24sp" 
     android:layout_weight="1" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:text="Voltas" 
     android:textSize="24sp" 
     android:layout_weight="1"/> 

</LinearLayout> 
+1

謝謝。現在它正在工作 – user185995

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="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Debanshu" 
    android:background="#ffa905" 
    android:textSize="24sp"/> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Chakraborty" 
    android:textSize="24sp" 
    android:background="#ffffff" 
    android:layout_weight="1" /> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Voltas" 
    android:textSize="24sp" 
    android:background="#008000" 
    android:layout_weight="1"/> 

享受!