4

TextView を使用したアクティビティがあります。画面の下部、中央に配置したいと思います。TextView が画面の幅に収まるようにしたいと思います。

これは私のXMLです:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#ffffff"
    tools:context=".ShowCard" >
    <TextView
        android:id="@+id/textView"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:background="#33000000"
        android:textColor="#000000"
        android:text="@string/lorem_ipsum" />

結果は私が期待していたものではありません。TextView は幅がフルスクリーンではありませんが、左右に小さな空きスペースが残ります (パディング/ボーダーのようですが、パディング/ボーダーを設定していません!)。

なぜなのかご存知ですか?提案?

4

5 に答える 5

3

すみません、私は愚かな男です !コンテナーの XML コードに 4 つのパディング行が含まれていることはわかりませんでした。

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

これらの行を削除したところ、すべてが正しく機能するようになりました!

ごめん。

于 2013-10-04T12:28:46.437 に答える
0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    tools:context=".ShowCard" >
    <TextView
        android:id="@+id/textView"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:background="#33000000"
        android:textColor="#000000"
        android:text="@string/lorem_ipsum" />

これを使って

于 2013-10-04T12:39:37.423 に答える
0
<TextView
android:id="@+id/textView"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#33000000"
android:textColor="#000000"
android:text="@string/lorem_ipsum" />

「fill_parent」属性を使用して、画面の幅全体を埋める必要があります。

于 2013-10-04T12:25:20.297 に答える
0

削除する

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

親の相対レイアウトから。

于 2013-10-04T12:36:11.410 に答える