关于组件先后顺序的问题

layout_height=match_parent :
虽然match_parent代表的是和父控件一样高,但是如果前面有其他控件,则先满足其他控件,如下
LinearLayout垂直布局,先定义了一个Button和一个TextView,所以ScrollView并没有占满整个屏幕;但是如果控件在ScrollView之后定义,比如TextView调整在ScrollView后面,则TextView不会显示出来

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<Button
android:id="@+id/send_request"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send Request"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_gravity="center"
/>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/response_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>



</LinearLayout>

结果

猜你喜欢

转载自blog.csdn.net/ling45654/article/details/77817165
今日推荐