java - 带有RelativeLayout的ScrollView

标签 java android android-layout scrollview android-relativelayout

我已经实现了一个LinearGraph并添加了LinearLayout(在xml中是LinearLayoutid="linearLayout1")。

现在我想在此图表之后添加表格,并且我需要使用 ScrollView 因为表格将有多于一行。

这是我尝试过但没有成功的 xml 之一...

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


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

                    <LinearLayout
                        android:layout_height="wrap_content"
                        android:layout_width="wrap_content"
                        android:paddingLeft="@dimen/activity_horizontal_margin"
                        android:paddingRight="@dimen/activity_horizontal_margin"
                        android:paddingTop="@dimen/activity_vertical_margin"
                        android:paddingBottom="@dimen/activity_vertical_margin"
                        android:id="@+id/linearLayout1"
                        android:orientation="vertical"
                        android:layout_above="@+id/tableLayout">
                    </LinearLayout>


                    <TableLayout
                        android:id="@+id/tableLayout"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="@drawable/my_drawable"
                        android:padding="5dp"
                        android:layout_alignParentBottom="true"
                        >

                        <TableRow
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" >

                            <TextView
                                android:id="@+id/home"
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:background="@drawable/my_drawable"
                                android:gravity="center"
                                android:padding="15dip"
                                android:text="Months" />

                            <TextView
                                android:id="@+id/status"
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:background="@drawable/my_drawable"
                                android:gravity="center"
                                android:padding="15dip"
                                android:text="Number of Visits" />
                        </TableRow>

                        <TableRow
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" >

                            <TextView
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:background="@drawable/my_drawable"
                                android:gravity="center"
                                android:padding="15dip"
                                android:text="January" />

                            <TextView
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:background="@drawable/my_drawable"
                                android:gravity="center"
                                android:padding="15dip"
                                android:text="1" />
                        </TableRow>

                        <TableRow
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" >

                            <TextView
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:background="@drawable/my_drawable"
                                android:gravity="center"
                                android:padding="15dip"
                                android:text="Februrary" />

                            <TextView
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:background="@drawable/my_drawable"
                                android:gravity="center"
                                android:padding="15dip"
                                android:text="" />
                        </TableRow>
                    </TableLayout>

       </RelativeLayout>
 </ScrollView>

最佳答案

try this

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


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



        <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:id="@+id/linearLayout1"
            android:orientation="vertical"
            android:layout_above="@+id/tableLayout"
            android:background="@android:color/darker_gray">
        </LinearLayout>


        <TableLayout
            android:id="@+id/tableLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:padding="5dp"
            android:layout_alignParentBottom="true">

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/darker_gray">

                <TextView
                    android:id="@+id/home"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="Months" />

                <TextView
                    android:id="@+id/status"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="Number of Visits" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/darker_gray">

                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="January" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="1" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/darker_gray">

                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="Februrary" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="2" />
            </TableRow>
        </TableLayout>

    </LinearLayout>
</ScrollView>

关于java - 带有RelativeLayout的ScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30745256/

相关文章:

android - 通过命令行将 keystore 密码传递给 Cordova Android

java - 登录尝试持续时间

android - Android 中的复选框验证

java - 我可以在没有 foreach 的情况下将 List<V> 转换为 Map<K, List<V>> 吗?

Java 中用于 SelectionKey、SelectableChannel 和 Selector 的 C# 类?

java - Jersey 2.0 内容长度未设置

java - 无法从外部存储打开文件以通过蓝牙共享

java - 即使存在实例,Room DB 也始终运行 if(INSTANCE==null) block

android - 在 AlertDialog 中显示长消息

android - 以编程方式更改按钮的样式值 android