2013-10-04 4 views
3

У меня есть активность с TextView. Я хотел бы выровнять его в нижней части экрана, в центре, и мне хотелось бы, чтобы 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 не является полноэкранным по ширине, но оставляет небольшое свободное пространство справа и слева (например, padding/border, но я не установил padding/border!).

Знаете ли вы, почему? Предложения?

+0

пожалуйста, добавьте код XML с точкой зрения корневой –

+1

Есть обивка или маржа в содержащем макете? Показать полный XML. – wyoskibum

ответ

4

попробовать этот

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" >  
     <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" /> 

    </RelativeLayout> 
+0

Он уже нашел свое решение. – GrIsHu

+0

@jayasree Спасибо! –

+0

@MassimoCostanzo Добро пожаловать –

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', он должен заполнить всю ширину экрана.

+0

Он уже нашел свое решение. – GrIsHu

+0

@Ndupza Спасибо! –

+0

@Ndupza Атрибут 'fill_parent' устарел. Он предложил использовать match_parent. –

3

Извините, я глупый парень! Я не вижу, что в коде XML контейнера были включены четыре дополняющих строк:

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

Я удалил эти строки, и теперь все работает правильно!

Извините.

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" 

от относительного расположения родительского.

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" /> 

использование этого

Смежные вопросы