嵌套的LinearLayout仅显示第一个视图 [英] Nested LinearLayout shows only the first View
问题描述
我看过一些问题,可能与此类似.但是,这些情况有所不同,有些不适用于初学者.
所以我最近才刚开始使用Android.请理解,我是*.xml
的新手.无论如何,我担心的是嵌套的LinearLayout
仅显示第一个View
.
I have seen some question the can be similar to this. However, those scenario were different and some are not for beginners.
So I just started Android recently. Please understand that I'm new to *.xml
. Anyway, my concern is regarding the nested LinearLayout
that only shows the first View
.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal">
<TextView
android:layout_gravity="center"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="20sp"
android:text="@string/app_title">
</TextView>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal">
<Button
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/button_ok"
android:onClick="changeMessage">
</Button>
<TextView
android:layout_gravity="center"
android:textSize="20sp"
android:id="@+id/this_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/sample_text">
</TextView>
</LinearLayout>
</LinearLayout>
这是到目前为止的XML.使用此代码,仅显示第一个TextView.
Here's the XML so far. With this code, only the first TextView is only showing.
推荐答案
android:layout_height="match_parent"
嵌套LinearLayout
的高度应为wrap_content
而不是match_parent
android:layout_height="match_parent"
the height of the nested LinearLayout
should be wrap_content
instead of match_parent
这篇关于嵌套的LinearLayout仅显示第一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!