带有表格布局和线性布局的滚动视图
scrollview with tablelayout and linearlayouts
我有一个 ScrollView
布局和一个 TableLayout
,其中我有一个 TableRow
,它由三个 TextViews
组成。
当我尝试将 TextViews
与屏幕对齐时出现问题。 TextViews
不占用屏幕的 space 并且有点塞满。
如果你们需要查看代码,我也附上了代码...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_reciept"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.spuck.LayoutTable">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="49dp"
android:src="@drawable/the_one_3"
android:id="@+id/the_one"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="@+id/scrollView2"
android:layout_below="@+id/relativeLayout"
android:layout_above="@+id/addButton">
<TableLayout
android:id="@+id/maintable"
android:layout_width="match_parent"
android:layout_height="300dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tableRow1">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/linear_layout_two_table_layout">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Date"
android:textAlignment="center"
android:textSize="20dp"
android:layout_weight="0.5"
android:background="@drawable/cell_shape"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Session Time"
android:textSize="20dp"
android:layout_weight="1"
android:background="@drawable/cell_shape"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Average Speed"
android:layout_gravity="center"
android:textSize="20dp"
android:layout_weight="1"
android:background="@drawable/cell_shape"
/>
</LinearLayout>
</TableRow>
</TableLayout>
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/addButton"
android:text="Scan item barcode"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
在 LinearLayout 中设置 android:layout_weight="2.5"
这是 LinearLayout children 的布局权重之和。在这个布局之后应该左右对齐。
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="2.5"
android:id="@+id/linear_layout_two_table_layout">
我有一个 ScrollView
布局和一个 TableLayout
,其中我有一个 TableRow
,它由三个 TextViews
组成。
当我尝试将 TextViews
与屏幕对齐时出现问题。 TextViews
不占用屏幕的 space 并且有点塞满。
如果你们需要查看代码,我也附上了代码...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_reciept"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.spuck.LayoutTable">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="49dp"
android:src="@drawable/the_one_3"
android:id="@+id/the_one"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="@+id/scrollView2"
android:layout_below="@+id/relativeLayout"
android:layout_above="@+id/addButton">
<TableLayout
android:id="@+id/maintable"
android:layout_width="match_parent"
android:layout_height="300dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tableRow1">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/linear_layout_two_table_layout">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Date"
android:textAlignment="center"
android:textSize="20dp"
android:layout_weight="0.5"
android:background="@drawable/cell_shape"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Session Time"
android:textSize="20dp"
android:layout_weight="1"
android:background="@drawable/cell_shape"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Average Speed"
android:layout_gravity="center"
android:textSize="20dp"
android:layout_weight="1"
android:background="@drawable/cell_shape"
/>
</LinearLayout>
</TableRow>
</TableLayout>
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/addButton"
android:text="Scan item barcode"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
在 LinearLayout 中设置 android:layout_weight="2.5"
这是 LinearLayout children 的布局权重之和。在这个布局之后应该左右对齐。
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="2.5"
android:id="@+id/linear_layout_two_table_layout">