如何使TextView块居中并且父级应该是x可滚动的?

时间:2019-01-21 23:47:54

标签: android xml android-studio android-layout

我正在尝试制作许多包含2-10个选项的选项容器。我想将这些选项放在一个容器中,该容器应将选项居中并使其垂直滚动,如下图所示。请帮忙。另外,如何使ScrollView的元素彼此相邻。

Image: enter image description here

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/light_black"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <RelativeLayout
        android:id="@+id/filter_options"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="visible"
        android:background="@color/secondary_color"
        android:orientation="vertical">

        <ScrollView
            android:background="@color/light_black"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_marginTop="100dp">

            <TextView
                android:layout_width="150dp"
                android:layout_height="fill_parent"
                android:text="Option 1"
                android:textAlignment="center"
                android:textSize="28dp"
                android:textColor="@color/white"
                android:background="@color/green">
            </TextView>
        </ScrollView>
    </RelativeLayout>
</android.support.constraint.ConstraintLayout>

0 个答案:

没有答案