gpt4 book ai didi

android - 在线性布局的不同方向上定位元素

转载 作者:搜寻专家 更新时间:2023-11-01 07:54:46 27 4
gpt4 key购买 nike

在我的布局中,我有一个带有 orientation="horizo​​ntal"
的 LinearLayout我的问题是我想在 textView 下面设置一个 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>

最佳答案

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

关于android - 在线性布局的不同方向上定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29575163/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com