是否必须在一个.xml文件中使用多个布局(线性布局,相对布局)

时间:2015-11-03 11:40:54

标签: android-layout android-studio displayobject

嘿,我是Android Studio中的新手,我有一个让我一直生气的问题.. 每当我使用单一布局时,例如相对布局。然后它工作正常,但有时组件(内容)在显示时无法正常显示。

我们是否需要为每个组件制作不同的布局?  请帮帮我。  在此先感谢。

2 个答案:

答案 0 :(得分:0)

基本没有布局是为了方便我们 每个布局都有自己独特的用途。

像...

  1. 线性布局适用于带重量的线性结构(可选)。
  2. 设置组件免费的
  3. 相对布局及其相对于彼此以及父级的位置。
  4. 框架布局,免费使用组件和重力位置。
  5. 网格结构中设置组件的
  6. 网格布局
  7. 对于某些复杂的设计,您可以使用嵌套的布局结构。

答案 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 .... !!!!

相关问题