由于循环依赖性,包装内容的相对布局变为全屏

时间:2016-04-02 06:22:37

标签: android android-layout

我正在粘贴下面的布局。

它具有外部相对布局,并且在其内部有两个布局,其id为l_first(线性布局)和滑块(相对布局)。这个滑块布局是我想要设计到设备屏幕底部的布局,并且应该采用内部的高度(几个布局和视图)。 l_first的底部应位于屏幕顶部和滑块顶部之间。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.raw.myapp.NewActivity"
android:background="#f2f2f2">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/l_first">

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:weightSum="1"
    android:id="@+id/slider"
    android:background="#e6e6e6">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Rental"
        android:layout_above="@+id/l_ten_ow"
        android:id="@+id/t_rental"
        android:layout_centerHorizontal="true"
        android:textSize="15dp"
        android:textColor="#000000"
        android:textIsSelectable="true" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/l_ptype"
        android:layout_centerHorizontal="true"
        android:id="@+id/l_ten_ow">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="I am a tenant"
            android:id="@+id/btn1"
            android:layout_gravity="center_vertical"
            android:layout_weight="0.5"
            android:textColor="#008000" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="I am a owner"
            android:id="@+id/btn2"
            android:layout_gravity="center_vertical"
            android:layout_weight="0.5" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/l_ptype_label"
        android:layout_centerHorizontal="true"
        android:id="@+id/l_ptype"
        android:paddingBottom="10dp"
        android:visibility="visible">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_weight="0.25"
            android:id="@+id/ib_home"
            android:src="@drawable/home1"
            android:background="#00000000"
            android:nestedScrollingEnabled="false" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_weight="0.25"
            android:id="@+id/ib_shop"
            android:src="@drawable/shop"
            android:background="#00000000" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:id="@+id/ib_industry"
            android:src="@drawable/industrial"
            android:background="#00000000"
            android:layout_weight="0.25" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:id="@+id/ib_office"
            android:src="@drawable/office"
            android:background="#00000000"
            android:layout_weight="0.25" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/r_p_subtype"
        android:layout_centerHorizontal="true"
        android:id="@+id/l_ptype_label"
        android:visibility="visible">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="home"
            android:id="@+id/textView3"
            android:layout_weight="0.25"
            android:textAlignment="center" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="shop"
            android:id="@+id/sho"
            android:layout_weight="0.25"
            android:textAlignment="center" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="industrial"
            android:id="@+id/ind"
            android:layout_weight="0.25"
            android:textAlignment="center" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="office"
            android:id="@+id/textView6"
            android:layout_weight="0.25"
            android:textAlignment="center" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/l_budget"
        android:id="@+id/r_p_subtype">

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_above="@+id/btn_oye"
        android:id="@+id/l_budget">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Budget"
            android:id="@+id/budget"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="10k"
            android:id="@+id/textView4"
            android:layout_below="@+id/budget"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <SeekBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/seekBar"
            android:layout_alignParentTop="true"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_toEndOf="@+id/budget"
            android:layout_toRightOf="@+id/budget"
            android:indeterminate="false"
            android:progressTint="#39ac73"
            android:thumb="@drawable/home" />

    </RelativeLayout>


    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:text="Oye"
        android:id="@+id/btn_oye"
        android:background="#39ac73"
        android:clickable="true"
        android:contextClickable="true" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

要达到目标,您应该使用线性布局

像这样:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.raw.myapp.NewActivity"
android:background="#f2f2f2">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="bottom">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/l_first"
        android:layout_weight="1">

        <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Button"
            android:id="@+id/button"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/slider"
        android:orientation="vertical"
        android:gravity="bottom"
        android:background="#e6e6e6">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="Rental"
            android:layout_above="@+id/l_ten_ow"
            android:id="@+id/t_rental"
            android:layout_centerHorizontal="true"
            android:textSize="15dp"
            android:textColor="#000000"
            android:textIsSelectable="true" />

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/l_ptype"
            android:layout_centerHorizontal="true"
            android:id="@+id/l_ten_ow">
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="I am a tenant"
                android:id="@+id/btn1"
                android:layout_gravity="center_vertical"
                android:layout_weight="0.5"
                android:textColor="#008000" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="I am a owner"
                android:id="@+id/btn2"
                android:layout_gravity="center_vertical"
                android:layout_weight="0.5" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/l_ptype_label"
            android:layout_centerHorizontal="true"
            android:id="@+id/l_ptype"
            android:paddingBottom="10dp"
            android:visibility="visible">

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:layout_weight="0.25"
                android:id="@+id/ib_home"
                android:src="@drawable/home1"
                android:background="#00000000"
                android:nestedScrollingEnabled="false" />

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:layout_weight="0.25"
                android:id="@+id/ib_shop"
                android:src="@drawable/shop"
                android:background="#00000000" />

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:id="@+id/ib_industry"
                android:src="@drawable/industrial"
                android:background="#00000000"
                android:layout_weight="0.25" />

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:id="@+id/ib_office"
                android:src="@drawable/office"
                android:background="#00000000"
                android:layout_weight="0.25" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/r_p_subtype"
            android:layout_centerHorizontal="true"
            android:id="@+id/l_ptype_label"
            android:visibility="visible">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="home"
                android:id="@+id/textView3"
                android:layout_weight="0.25"
                android:textAlignment="center" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="shop"
                android:id="@+id/sho"
                android:layout_weight="0.25"
                android:textAlignment="center" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="industrial"
                android:id="@+id/ind"
                android:layout_weight="0.25"
                android:textAlignment="center" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="office"
                android:id="@+id/textView6"
                android:layout_weight="0.25"
                android:textAlignment="center" />
        </LinearLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/l_budget"
            android:id="@+id/r_p_subtype">

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_above="@+id/btn_oye"
            android:id="@+id/l_budget">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Budget"
                android:id="@+id/budget"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="10k"
                android:id="@+id/textView4"
                android:layout_below="@+id/budget"
                android:layout_centerVertical="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />

            <SeekBar
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/seekBar"
                android:layout_alignParentTop="true"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_toEndOf="@+id/budget"
                android:layout_toRightOf="@+id/budget"
                android:indeterminate="false"
                android:progressTint="#39ac73"
                android:thumb="@drawable/home" />

        </RelativeLayout>


        <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:text="Oye"
            android:id="@+id/btn_oye"
            android:background="#39ac73"
            android:clickable="true"
            android:contextClickable="true" />

    </LinearLayout>

</LinearLayout>
</RelativeLayout>

有两个重要的注释:

  
      
  1. 你的线性布局应该有重力底部,这意味着它从底部计算高度。
  2.   
  3. 您想要获得剩余空间的视图应该具有1的重量!!!
  4.   
相关问题