0

我有这个 xml 代码,我想将其用作加载屏幕的基础......

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

    <TextView
        android:id="@+id/loading_message"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="LOADING..." />
</RelativeLayout>

这是在 main_loading.xml 和 TextView 应该清楚地居中,并且在 elicipse XML 预览中,它是......(所以现在一切都很好:))

然而:

我将这个 xml 与另一个一起使用,所以我正在使用:

    RelativeLayout mainLayout = (RelativeLayout)findViewById(R.id.llid);
    mainLayout.removeAllViews();
    LayoutInflater inflater = getLayoutInflater();
    mainLayout.addView(inflater.inflate(R.layout.main_loading, null));

在 xml 之间进行交换,这在模拟器上都可以正常工作,除了 Textview 的居中...(它保持未对齐 - 左上角)这是为什么?如何使用上述充气机/布局代码居中?

非常感谢。

编辑:我的其他 XML 文件...

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

<EditText android:id="@+id/edit_message"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:hint="@string/edit_message" />

<Button android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send"
    android:onClick="Login" 
    android:layout_toRightOf="@id/edit_message" />

</RelativeLayout>
4

0 回答 0