Android 文本视图在线性(垂直)布局内不可见?
这是我的XML代码。 我有一个外部垂直线性布局。 其中有一个包含两个文本视图的水平线性布局。 水平布局下方是另一个文本视图。但这是不可见的Android 文本视图在线性(垂直)布局内不可见?,android,android-layout,Android,Android Layout,这是我的XML代码。 我有一个外部垂直线性布局。 其中有一个包含两个文本视图的水平线性布局。 水平布局下方是另一个文本视图。但这是不可见的 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schema
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.example.praveenmuthukumarana.coursework1_quizapp.GameActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="250dp"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:background="@android:color/holo_green_dark"/>
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/holo_red_dark"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@android:color/holo_blue_dark"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
我期待着这样的事情
如何实现这一点?将水平线性布局的高度设置为包裹内容
,如中所示
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="250dp"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:background="@android:color/holo_green_dark"/>
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/holo_red_dark"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@android:color/holo_blue_dark"/>
</LinearLayout>
将水平线性布局的高度
设置为包裹内容
如中所示
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="250dp"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:background="@android:color/holo_green_dark"/>
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/holo_red_dark"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@android:color/holo_blue_dark"/>
</LinearLayout>
将第二行的高度设为换行内容。
线性布局视图与文本视图重叠,这就是文本视图不可见的原因
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="250dp"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:background="@android:color/holo_green_dark"/>
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/holo_red_dark"/>
</LinearLayout>
将第二行的高度设为换行内容。
线性布局视图与文本视图重叠,这就是文本视图不可见的原因
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="250dp"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:background="@android:color/holo_green_dark"/>
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/holo_red_dark"/>
</LinearLayout>
将内线布局的高度设置为“包裹内容”,您已将其设置为“匹配父项”
换行内容->换行内容,仅取视图或其内部视图所需的大小并换行
match_parent->匹配其父容器的大小,占用其父容器的所有空间
此处,您的内部线性布局占用了其父视图的所有空间,没有留下任何空间供其他视图绘制将内部线性布局的高度设置为“包裹内容”,您已将其设置为“匹配父视图”
换行内容->换行内容,仅取视图或其内部视图所需的大小并换行
match_parent->匹配其父容器的大小,占用其父容器的所有空间
在这里,内部线性布局占用了其父视图的所有空间,没有留下任何空间供其他视图绘制设置第二个线性布局的高度以包裹内容。或者两者都是线性布局。这是因为高度=匹配父项,我认为,将其更改为换行内容。之后将第二个线性布局的高度设置为换行内容。或者两者都是线性布局。这是因为高度=匹配父项。我想,将其更改为“包装内容”。之后它将起作用