Android线性布局困难
我有一个纵向xml布局文件,其中包含一个文本框,位于ImageView的顶部。这是使用垂直线性布局完成的。问题是,我已经创建了一个横向xml布局文件,但我不知道如何在这个特定布局文件的ImageView上方插入一个文本框。不知什么原因,我有麻烦了 总之,我想复制我的肖像xml中的样式(关于文本框和ImageView关系)。下面的图片应该清楚地说明我的意思。图标是故意用灰色覆盖的,但你知道了大概的意思 我的环境xml:Android线性布局困难,android,android-layout,android-linearlayout,Android,Android Layout,Android Linearlayout,我有一个纵向xml布局文件,其中包含一个文本框,位于ImageView的顶部。这是使用垂直线性布局完成的。问题是,我已经创建了一个横向xml布局文件,但我不知道如何在这个特定布局文件的ImageView上方插入一个文本框。不知什么原因,我有麻烦了 总之,我想复制我的肖像xml中的样式(关于文本框和ImageView关系)。下面的图片应该清楚地说明我的意思。图标是故意用灰色覆盖的,但你知道了大概的意思 我的环境xml: <?xml version="1.0" encoding="utf-8"
<?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>
只需将CropImageView包装在布局中,例如线性布局
<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>
为什么选择两种布局??您可以维护纵向和横向的单一布局。@Lokesh我知道,但我的纵向xml有一个问题(一旦我将手机切换到横向模式)。所以我恐怕这不是一个选择。不过谢谢你的建议:)谢谢!这就成功了。我尝试了同样的方法,但我没有使用权重,我想知道为什么我的textView不会出现!哈哈……帮我省了点麻烦。:)