0

我正在尝试在我的应用程序的 Android 版本上获得以下外观(来自我的 iOS 应用程序的屏幕截图)。

我的 iOS 应用程序的屏幕截图

我在Android中定义了我的布局文件如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <EditText
        android:id="@+id/postTextTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/shareLILayout"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:ems="10"
        android:gravity="top|left|start"
        android:inputType="textMultiLine" >

        <requestFocus />
    </EditText>

    <LinearLayout 
        android:id="@+id/shareLILayout"
        android:layout_alignParentBottom="true"
        android:background="#999999"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:orientation="horizontal" >
        
        <ImageButton
            android:contentDescription="@string/li_btn_desc"
            android:id="@+id/postToLIButton"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginRight="5dp"
            android:layout_marginBottom="5dp"
            android:background="@android:color/transparent"
            android:src="@drawable/linkedin_switch_off" />
                
        <TextView
            android:id="@+id/postToLITextView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/share_on_linkedin"
            android:layout_gravity="center_vertical"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="14sp" />

    </LinearLayout>
</RelativeLayout>

如果我交换上面的 ImageButton 和 TextView,我的应用程序会因 RuntimeException 而崩溃!此外,我无法将文本居中以使其与按钮的中心对齐。我究竟做错了什么?

4

1 回答 1

2

只需交换ImageButtonTextView顺序。您的运行时错误要么是无关的,要么是由于在需要重新部署项目之前需要清理项目(有时资源 ID 变得很奇怪)。也android:gravity="center_vertical"用于您TextView正确居中

于 2013-06-21T15:37:56.617 回答