Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在线性布局的不同方向上定位图元_Android_Android Linearlayout - Fatal编程技术网

Android 在线性布局的不同方向上定位图元

Android 在线性布局的不同方向上定位图元,android,android-linearlayout,Android,Android Linearlayout,在我的布局中,我有一个带有orientation=“horizontal” 我的问题是我想在文本视图下面设置一个ImageView,有什么方法可以做到这一点吗?(我知道我可以用RelativeLayout实现这一点,但我不想在这里更改LinearLayout) 这是我的代码: <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" a

在我的布局中,我有一个带有
orientation=“horizontal”

我的问题是我想在文本视图下面设置一个ImageView,有什么方法可以做到这一点吗?(我知道我可以用RelativeLayout实现这一点,但我不想在这里更改LinearLayout)
这是我的代码:

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.0"
        android:layout_marginBottom="5dp"
        android:background="@drawable/shape_edit_text"
        android:gravity="center_vertical">

    <ImageView
            android:id="@+id/imgFlag"
            android:layout_width="16dp"
            android:layout_height="16dp"
            android:layout_marginLeft="8dp"/>

    <TextView
            android:id="@+id/txtCountries"
            style="@style/Field.EditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.7"
            android:layout_marginRight="1dp"/>

    <EditText
            android:id="@+id/edtPhoneNumber"
            style="@style/Field.EditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.3"
            android:layout_marginLeft="1dp"
            android:hint="@string/phone_number"
            android:inputType="phone"/>
</LinearLayout>

是的,有一种方法可以做到这一点。您需要在布局中创建布局,并将有问题的两个元素放置在内部布局中。它可以是垂直方向的线性布局,因此其中的两个元素垂直堆叠

这是@IIya Kogan描述的一个样本

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.0"
        android:layout_marginBottom="5dp"
        android:background="@drawable/shape_edit_text"
        android:gravity="center_vertical">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <ImageView
                android:id="@+id/imgFlag"
                android:layout_width="16dp"
                android:layout_height="16dp"
                android:layout_marginLeft="8dp"/>

            <TextView
                android:id="@+id/txtCountries"
                style="@style/Field.EditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.7"
                android:layout_marginRight="1dp"/>
        </LinearLayout>

        <EditText
            android:id="@+id/edtPhoneNumber"
            style="@style/Field.EditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.3"
            android:layout_marginLeft="1dp"
            android:hint="@string/phone_number"
            android:inputType="phone"/>
</LinearLayout>


可以使用android:orientation=“vertical”的新线性布局,也可以使用RelativeLayou

谢谢,但没有添加新布局的其他方法吗?我想在RelativeLayout中找一些类似于“layout_below”的东西,它们在LinearLayout中工作。too@y.feiziLinearLayout没有这样的属性。您确定吗?此ImageView是唯一必须与其他元素处于不同位置的元素,我不想为其添加新布局或更改父元素!为什么不添加布局?费用是多少?@y.feizi您可以在API文档中检查LinearLayout的完整属性。谢谢美味:)我在问这个问题之前试过这个,但阅读我在kogan答案下的评论,了解我为什么问这个问题