[英]TableLayout going out of screen
I can't make my Android TableLayout works, it's going out of the screen. 我无法使我的Android TableLayout正常运行,但该屏幕不在屏幕上。 I tried layout:weight and android:shrinkColumns="*". 我尝试了layout:weight和android:shrinkColumns =“ *”。
My xml: 我的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" />
Screenshots: 屏幕截图:
The difference between those images is only shorter/longer text. 这些图像之间的区别只是较短/较长的文本。
I was trying some combinations with wrap_content/match_parent, but it didn't help me. 我正在尝试使用wrap_content / match_parent进行某些组合,但这对我没有帮助。
Can you help me? 你能帮助我吗? Thanks in advance. 提前致谢。
EDIT to ysl's answer: the result of your code 编辑ysl的答案: 代码的结果
Try following code might be helpful : 尝试以下代码可能会有所帮助:
<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>
Working code if someone needs: 如果有人需要的工作代码:
<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.