【问题标题】:Android place an image view between two viewsAndroid 在两个视图之间放置一个图像视图
【发布时间】:2014-10-26 21:53:03
【问题描述】:

我需要创建一个如图所示的布局。 带有箭头的圆形按钮需要正好位于蓝色和灰色背景之间。 如果没有精确指定边距,我很难放置它,这是我不想做的事情,因为不能保证它在所有分辨率和设备上看起来都很好。 我将不胜感激一个 xml 示例

谢谢!

【问题讨论】:

标签: android android-layout android-xml


【解决方案1】:

使用所需的drawable..希望它有效..您可以根据需要设置宽度和高度。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

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

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#e6e6e6"
                android:orientation="vertical" >
            </LinearLayout>
        </LinearLayout>

        <ImageView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/arrow" />
    </FrameLayout>

</LinearLayout>

【讨论】:

  • 如果布局的权重为 3 和 7 怎么办。你如何将箭头保持在两个布局的精确交叉点?