Android线性布局困难

时间:2014-03-19 04:58:35

标签: android android-layout android-linearlayout

我有一个肖像xml布局文件,其中包含一个文本框,该文本框放在ImageView上。这是使用垂直线性布局完成的。麻烦的是,我创建了一个横向xml布局文件,但我不知道如何在这个特定的布局文件中插入ImageView上方的文本框。出于某种原因,我遇到了麻烦。

总结一下,我想复制我的肖像xml中的样式(关于文本框和ImageView关系)。下面的图片应该清楚地说明我的意思。图标有目的地用灰色覆盖,但你会得到一般的想法。

My Landscape xml:

<?xml version="1.0" encoding="utf-8"?>

<!-- This relative layout will center EVERYTHING within it. Do not touch this functionality. -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relative_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <com.edmodo.cropper.CropImageView
            xmlns:custom="http://schemas.android.com/apk/res-auto"
            android:id="@+id/CropImageView"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:gravity="center" >
        </com.edmodo.cropper.CropImageView>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".12"
            android:gravity="center" >

            <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical"
                tools:ignore="UselessParent" >

                <ImageView
                    android:id="@+id/button1of3"
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:contentDescription="@string/button1_description"
                    android:src="@drawable/ic_action_rotate"
                    android:visibility="invisible"
                    tools:ignore="Suspicious0dp" />

                <ImageView
                    android:id="@+id/button2of3"
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:contentDescription="@string/button3_description"
                    android:padding="2dp"
                    android:src="@drawable/ic_action_camera" />

                <ImageView
                    android:id="@+id/button3of3"
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:contentDescription="@string/button4_description"
                    android:src="@drawable/ic_action_feed" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

Landscape layout Portrait layout

1 个答案:

答案 0 :(得分:1)

将CropImageView包装在布局中,例如,LinearLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relative_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ProgressBar
    android:id="@+id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/test"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight=".12"
            android:text="Test" />

        <com.edmodo.cropper.CropImageView
            xmlns:custom="http://schemas.android.com/apk/res-auto"
            android:id="@+id/CropImageView"
            android:layout_height="0dip"
            android:layout_width="fill_parent"
            android:layout_weight=".88"
            android:gravity="center" >
        </com.edmodo.cropper.CropImageView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight=".12"
        android:gravity="center" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical"
            tools:ignore="UselessParent" >

            <ImageView
                android:id="@+id/button1of3"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:contentDescription="@string/button1_description"
                android:src="@drawable/ic_action_rotate"
                android:visibility="invisible"
                tools:ignore="Suspicious0dp" />

            <ImageView
                android:id="@+id/button2of3"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:contentDescription="@string/button3_description"
                android:padding="2dp"
                android:src="@drawable/ic_action_camera" />

            <ImageView
                android:id="@+id/button3of3"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:contentDescription="@string/button4_description"
                android:src="@drawable/ic_action_feed" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>