嘿,我是Android Studio中的新手,我有一个让我一直生气的问题.. 每当我使用单一布局时,例如相对布局。然后它工作正常,但有时组件(内容)在显示时无法正常显示。
我们是否需要为每个组件制作不同的布局? 请帮帮我。 在此先感谢。
答案 0 :(得分:0)
基本没有布局是为了方便我们 每个布局都有自己独特的用途。
像...
对于某些复杂的设计,您可以使用嵌套的布局结构。
答案 1 :(得分:0)
所有布局都具有独特的功能。 取决于风格,哪种布局适合。
线性和相对是最常用的。不同的是...... 在相对布局中,所有小部件都由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 .... !!!!