我无法使我的Android TableLayout正常工作,它超出了屏幕范围。我尝试过layout:weight和android:shrinkColumns="*"。
我的xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="dindz.oso.MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark" />
<TableLayout
android:id="@+id/tl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/toolbar"
android:gravity="center_horizontal"
android:shrinkColumns="*"
android:stretchColumns="0,1,2,3">
<TableRow
android:id="@+id/header_tabeli"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="#000000"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text=" Data\nstartu "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold"
android:layout_weight="1"/>
<TextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="1"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="Stacja"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="2"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="Rodzaj"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="3"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="Poziom"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#000000">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:gravity="center"
android:text="data 2301.23.23 11:23 ksajd"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="1"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:gravity="center"
android:text="stacja wrocław ul. długiego 32"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="2"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:gravity="center"
android:text="rodzaj no2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="3"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:gravity="center"
android:text="4"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
</TableLayout>
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tl"
android:layout_centerHorizontal="true"
android:ems="10"
android:inputType="textPersonName"
android:text="Brak aktywnych alarmów"
android:visibility="invisible" />
截图:
这些图片之间唯一的区别就是文字的长度。
我尝试过使用wrap_content/match_parent来组合,但是并没有帮助到我。
你能帮帮我吗?提前致谢。
编辑ysl的回答: 你的代码的结果