我看到一些問題可以與此類似。但是,這些情況有所不同,有些不適合初學者。
所以我剛剛開始Android。請理解我是*.xml
的新手。無論如何,我關心的是嵌套的LinearLayout
只顯示第一個View
。嵌套的LinearLayout只顯示第一個視圖
<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只顯示。
感謝您的反饋意見。我會在重新啓動我的電腦後嘗試。 –
無論如何,這不是一項任務。爲了我的學習,如果我可能會問,將layout_height設置爲match_parent後發生了什麼?我在做Java,所以我認爲ViewGroup的功能就像一個JPanel。 –
與match_parent視圖(LineraLayout)將作爲其父項高。有了wrap_content,它會很高,因爲它的內容 – Blackbelt