Wak*_*viL 8 android relativelayout android-layout android-framelayout
我是Android编程的新手,但从我对文档中的布局了解多少,当您需要基于某些规则的视图时,RelativeLayout主要用于想要重叠视图时的FrameLayout.
但遗憾的是,对于以下程序,我使用RelativeLayout完成了FrameLayout的工作.我完成了我的工作,但为了理解,我错过了一些区别的东西吗?另外,按钮是如何覆盖我的图像的?(即使其他图像重叠.)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ic_launcher"
/>
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:layout_alignParentTop="true"
android:layout_alignLeft="@id/imageView1"
/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1.0" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:text="Login" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:text="Register" />
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:text="Try application" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
Sli*_*ito 18
将RelativeLayout可以使用:
android:layout_toEndOf="@id/some_view"
android:layout_toStartOf="@id/some_view"
android:layout_above="@id/some_view"
android:layout_below="@id/some_view"
Run Code Online (Sandbox Code Playgroud)
确保视图阵容相对于彼此正确.FrameLayout非常相似,只是它只使用重力来显示它的视图(没有关系).
我还建议你看一下ConstraintLayout组件.ConstraintLayout允许您使用平面视图层次结构创建大型复杂布局(无嵌套视图组).它与RelativeLayout类似,因为所有视图都根据兄弟视图和父布局之间的关系进行布局,但它比RelativeLayout更灵活,更易于使用Android Studio的布局编辑器.
Xar*_*mer 10
RelativeLayout基于视图的关系.它是一个布局管理器,可帮助您根据某些规则排列UI元素.您可以指定以下内容:将此对齐到父项左边缘,将其放在此元素的左侧/右侧等.
FrameLayout允许沿Z轴放置.也就是说,您可以将视图元素叠加在另一个之上.