[英]How can TextView be aligned right next to a Buttin in LinearLayout
[英]How can TextView be aligned right next to an ImageButton in LinearLayout
我試圖在ImageButton
旁邊有一個TextView
。 但是, TextView
對齊不正確。 我希望它從與ImageButton
相同的頂部開始。
現在是這樣的:
這是我的布局:
<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>
將此屬性設置為在TextView
標簽內查看元素android:gravity="top"
。
我希望這會起作用。
嘗試這個..
為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>
或使用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>
試試看:
<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"/>
您必須執行android:layout_height =“ match_parent”並設置重心。
使用以下代碼:-
<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>
嘗試,
android:gravity="top"
在textview中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.