Android线性布局图像在同一水平线上查看和编辑文本
我正在尝试将Android线性布局图像在同一水平线上查看和编辑文本,android,android-layout,Android,Android Layout,我正在尝试将ImageView和EditText放在同一行上 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/image_flag" android:layout_
ImageView
和EditText
放在同一行上
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/image_flag"
android:layout_width="25dp"
android:layout_height="30dp"
android:layout_gravity="bottom"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
<!-- Phone number Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="8"
android:drawablePadding="5dp"
android:gravity="center_vertical">
<EditText
android:id="@+id/signin_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number"
android:inputType="phone" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
如何使电话号码视图和图像位于同一中心线上?谢谢。向线性布局添加android:gravity=“center\u vertical”
向线性布局添加android:gravity=“center\u vertical”
您可以在编辑文本中使用drawableLeft
属性,而不是像这样获取另一个图像视图
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- Phone number Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="8"
android:drawablePadding="5dp"
android:gravity="center_vertical">
<EditText
android:id="@+id/signin_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@mipmap/ic_launcher"
android:hint="Phone Number"
android:inputType="phone" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
您可以在EditText
中使用drawableLeft
属性,而不是像这样获取另一个ImageView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- Phone number Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="8"
android:drawablePadding="5dp"
android:gravity="center_vertical">
<EditText
android:id="@+id/signin_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@mipmap/ic_launcher"
android:hint="Phone Number"
android:inputType="phone" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
如果您不需要“LinearLayout”,您可以使用“RelativeLayout”作为容器,然后使用android:layout_alignBaseline=“@+id/title”轻松完成此任务
在各个视图中。如果您不需要“LinearLayout”,您可以使用“RelativeLayout”作为容器,然后在各个视图中使用android:layout\u alignBaseline=“@+id/title”轻松完成此任务。不起作用。我必须调整图像视图上的边距底部似乎对我来说工作得很好,你能发布整个布局的xml代码吗,也许另一个组件正在影响线性布局的行为不工作。我必须调整图像视图上的边距底部似乎对我来说非常适合,你能发布整个布局的xml代码吗,也许另一个组件影响了线性布局的行为请参见下面我的答案。谢谢。请看下面我的答案。谢谢