我不能讓我的Android TableLayout工作,它會離開屏幕。 我試過layout:weight和android:shrinkColumns =「*」。TableLayout走出屏幕
我的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的回答是: the result of your code
我只是在你的代碼更改文本長在第二個TableRow的第二個textview中。不起作用(在EDIT上面的屏幕)。仍然感謝您的帖子。 – Maciek
更改 android:stretchColumns =「0,1,2,3」android:stretchColumns =「*」 – YoLo
我只是修改你的答案(改變所有電視寬度爲0dp),它的確有竅門。謝謝你。 的TableRow: 的android:layout_width = 「0dp」 機器人:layout_height = 「WRAP_CONTENT」 的TextView: 的android:layout_width = 「0dp」 機器人:layout_height = 「WRAP_CONTENT」 我不能贊成票你:/ – Maciek