如何挤压3` <include layout =“`”in =“”one =“”row?=“”

时间:2015-08-30 13:25:57

标签: java android android-layout android-relativelayout

=“”

我有这个XML:

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity$PlaceholderFragment">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="100dip"
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dip"
        android:id="@+id/image"
        android:src="@android:drawable/arrow_up_float"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dip"
        android:orientation="horizontal"
        android:layout_below="@+id/image">

        <include layout="@layout/time_box"/>

        <include layout="@layout/time_box" />

        <include layout="@layout/time_box" />

    </LinearLayout>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button"
        android:layout_marginBottom="27dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:hint="enter your name"/>

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:layout_above="@+id/button"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="34dp" />

</RelativeLayout>

enter image description here

xml

<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".MainActivity$PlaceholderFragment"
    android:weightSum="1">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="100dip"
        android:src="@android:drawable/alert_dark_frame"
        android:id="@+id/textView1"
        android:gravity="center"
        android:background="#152"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="10dip"
        android:text="New Text"
        android:textColor="#FFFFFF"
        android:id="@+id/textView2"
        android:background="#120"
        android:gravity="center"
        android:layout_weight="0.07" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="30dip"
        android:text="--"
        android:textSize="30dp"
        android:id="@+id/textView3"
        android:gravity="center"
        android:layout_weight="0.88" />

</LinearLayout>

enter image description here

我希望它最终看起来像:

enter image description here

你的定位和尺码会改变什么?

1 个答案:

答案 0 :(得分:0)

使用布局权重。

<include layout="@layout/time_box" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/>

为每个包含的视图执行此操作