嘿,那裏我是Android Studio中的新手,我有一個問題讓我始終處於瘋狂狀態...... 每當我使用單一佈局例如相對佈局。那麼它工作正常,但有時組件(內容)在顯示時不能正常顯示。是否需要在一個.xml文件中使用多個佈局(線性佈局,相對佈局)
我們是否需要爲每一個組件做出不同的佈局? 請幫幫我。 在此先感謝。
嘿,那裏我是Android Studio中的新手,我有一個問題讓我始終處於瘋狂狀態...... 每當我使用單一佈局例如相對佈局。那麼它工作正常,但有時組件(內容)在顯示時不能正常顯示。是否需要在一個.xml文件中使用多個佈局(線性佈局,相對佈局)
我們是否需要爲每一個組件做出不同的佈局? 請幫幫我。 在此先感謝。
沒有基本的佈局是我們的方便, 和每個佈局有其獨特的用途。
像...
對於一些複雜的設計,你可以使用佈局的嵌套結構。
所有佈局都有獨特的功能。 取決於風格,哪種佈局適合這種風格。
線性和相對最常用。不同的是... 在相對佈局中,所有的部件都由ID控制。 示例...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:text="Hello"
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_below="@+id/text1"
android:text="Done"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
在LinearLayout中。你有重量。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:layout_weight="1"
android:text="Hello"
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_weight="1"
android:layout_below="@+id/text1"
android:text="Done"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
在網格佈局中有行和列來調整您的佈局。
請注意.... 一個活動有多個佈局...... :) Cheeers .... !!!!
非常感謝你們,我希望我們都需要在android的世界中學習很多東西:)最好的祝福 – Zain1122
謝謝拉維的好解釋:) – Zain1122