[英]TableLayout going out of screen
我無法使我的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的答案: 代碼的結果
嘗試以下代碼可能會有所幫助:
<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">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="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="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:collapseColumns=" Data\nstartu "
android:gravity="center"
android:shrinkColumns="*"
android:stretchColumns="*">
<TableRow
android:id="@+id/header_tabeli"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#000000"
android:gravity="center">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_column="0"
android:background="#FFFFFF"
android:gravity="center"
android:text="Stacja ugugugugugug "
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_column="1"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="Stacja ugugugugugug"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_column="2"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="Rodzaj"
android:textStyle="bold" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="Poziom"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="#000000">
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="stacja Data\nstartu " />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="stacja Data\nstartu " />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_column="2"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="rodzaj no2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_column="3"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="4" />
</TableRow>
</TableLayout>
</RelativeLayout>
如果有人需要的工作代碼:
<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">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="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="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="@+id/toolbar"
android:layout_alignParentStart="true">
<!-- android:shrinkColumns="*"
android:stretchColumns="*"
android:collapseColumns="*"-->
<TableRow
android:id="@+id/header_tabeli"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#000000"
android:gravity="center">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_weight="2"
android:layout_margin="1dp"
android:background="#FFFFFF"
android:gravity="center"
android:text="Data\nstartu"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_column="1"
android:layout_margin="1dp"
android:layout_weight="4"
android:background="#FFFFFF"
android:gravity="center"
android:text="Stacja"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
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"
android:textStyle="bold" />
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
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="Poziom"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="#000000">
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_margin="1dp"
android:layout_weight="2"
android:background="#FFFFFF"
android:gravity="center"
android:text="9/21/2017 1:52:00 PM" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_column="1"
android:layout_margin="1dp"
android:layout_weight="4"
android:background="#FFFFFF"
android:gravity="center"
android:text="Wrocław, ul. Wyb. J.Conrada-Korzeniowskiego 18" />
<!--Wrocław, ul. Wyb. J.Conrada-Korzeniowskiego 18-->
<TextView
android:layout_width="0dp"
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="no2" />
<TextView
android:layout_width="0dp"
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" />
</TableRow>
</TableLayout>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.