[英]How can TextView be aligned right next to an ImageButton in LinearLayout
I am trying to have a TextView
right next to an ImageButton
. 我试图在
ImageButton
旁边有一个TextView
。 However, the TextView
isn't aligned well. 但是,
TextView
对齐不正确。 I want it to start at the same top position as the ImageButton
. 我希望它从与
ImageButton
相同的顶部开始。
This is how it looks right now: 现在是这样的:
Here is my layout: 这是我的布局:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:orientation="horizontal">
<ImageButton
android:id="@+id/myimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:src="@drawable/myimage"/>
<TextView
android:id="@+id/mytexview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp"
android:text="My Text"
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:textColor="#DF533B"
/>
</LinearLayout>
set this property to view element android:gravity="top"
inside the TextView
tag. 将此属性设置为在
TextView
标签内查看元素android:gravity="top"
。
I hope this will work. 我希望这会起作用。
Try this.. 尝试这个..
Add android:layout_gravity="center"
for both ImageButton
and TextView
为
ImageButton
和TextView
添加android:layout_gravity="center"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/myimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#FFFFFF"
android:src="@drawable/myimage" />
<TextView
android:id="@+id/mytexview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="My Text"
android:textColor="#DF533B"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
Or Use android:drawableLeft="@drawable/ic_launcher"
and add android:gravity="center"
for that TextView
或使用
android:drawableLeft="@drawable/ic_launcher"
并为该TextView
添加android:gravity="center"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/mytexview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:drawableLeft="@drawable/ic_launcher"
android:gravity="center"
android:text="My Text"
android:textColor="#DF533B"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
Try that: 试试看:
<TextView
android:id="@+id/mytexview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp"
android:drawableLeft="@drawable/myimage"
android:text="My Text"
android:textStyle="bold"
android:gravity="center_vertical"
android:layout_marginLeft="5dp"
android:textColor="#DF533B"/>
You have to do android:layout_height="match_parent" and set gravity center . 您必须执行android:layout_height =“ match_parent”并设置重心。
use below code:- 使用以下代码:-
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/myimage"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:src="@drawable/myimage" />
<TextView
android:id="@+id/mytexview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:text="My Text"
android:gravity="center"
android:textColor="#DF533B"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
try, 尝试,
android:gravity="top"
in textview android:gravity="top"
在textview中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.