我已经实现了一个LinearGraph
并添加了LinearLayout
(在xml中是LinearLayout
和id="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/