我跟着this approach,但是使用FrameLayout我只能选择" orange"使用layout_gravity
查看,当我尝试在图片中解释时,我不知道布局'高度,因为两者都用layout_weight测量。
我的布局:
<?xml version="1.0" encoding="utf-8"?>
<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="onit.radiolisten.MainActivity">
<FrameLayout
android:id="@+id/layout_container_activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- TOP LAYOUT, THE GREEN ONE ON THE IMAGE -->
<LinearLayout
android:id="@+id/layout_top_activity_main"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="2"
android:background="@color/colorPrimary"
android:orientation="vertical"></LinearLayout>
<!-- BOTTOM LAYOUT, THE BLUE ONE ON THE IMAGE -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#e6e6e6">
</RelativeLayout>
</LinearLayout>
<!-- THIS IS THE IMAGE I WANT TO POSITION -->
<ImageView
android:id="@+id/btn_play_radio"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center"
android:src="@drawable/play_icon" />
</FrameLayout>
</LinearLayout>
这可以仅用XML完成吗?
答案 0 :(得分:6)
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<--main layout-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<--top layout-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="20dp"
android:layout_weight="0.4"
android:gravity="bottom|center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:background="@color/callingscreen_color"
android:gravity="center|top" />
</LinearLayout>
<--layout for img-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:gravity="center|top">
<--IMage u want to put-->
<ImageView
android:id="@+id/ivimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>