在android中覆盖3个相同大小的文本视图的水平“线”

时间:2017-02-26 17:02:37

标签: android xml android-layout

我试图创建一个布局,将水平线“划分”3并用3个文本视图填充它。即使以下不是我想要达到的目标,样本仍在遵循。 Sample design

所以我开始写这个并看到一些问题。 1)我设法将标题写在彼此旁边,但它们之间有空格。 2)他们不覆盖整个屏幕 3)颜色和背景形状不同,但我可以使用ID来纠正它。

所以这是我到目前为止所做的。

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/name_text_view"
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:paddingTop="40dp"
    android:paddingRight="40dp"
    android:paddingBottom="40dp"
    android:paddingLeft="40dp"
    android:textColor="@color/white"
    android:gravity="center">

</TextView>

1 个答案:

答案 0 :(得分:0)

您需要使用重量属性。

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

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

     <TextView
        android:id="@+id/sports"
        android:text="Sports"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />
    <TextView
        android:id="@+id/science"
        android:text="Science"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />
    <TextView
        android:id="@+id/music"
        android:text="Music"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />
    </LinearLayout>

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

     <TextView
        android:id="@+id/sports"
        android:text="Sports"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />
    <TextView
        android:id="@+id/science"
        android:text="Science"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />
    <TextView
        android:id="@+id/music"
        android:text="Music"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />
    </LinearLayout>

</LinearLayout>
相关问题