2016-08-14 68 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"/> 

享受!