0

我试图TextViewImageButton. 但是,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>
4

5 回答 5

2

设置此属性以查看标签android:gravity="top"内的元素。TextView

我希望这会奏效。

于 2014-05-21T12:12:00.533 回答
1

试试看:

<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"/>
于 2014-05-21T12:13:13.647 回答
1

尝试这个..

android:layout_gravity="center"为两者添加ImageButtonTextView

<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"并添加android:gravity="center"TextView

<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>
于 2014-05-21T12:05:24.863 回答
0

你必须做 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>
于 2014-05-21T12:04:54.397 回答
0

尝试,

android:gravity="top"在文本视图中

于 2014-05-21T12:07:02.757 回答