2013-06-21 4 views
3

Я пытаюсь разместить TextView на ImageView в нижнем центре RelativeLayout. Я могу разместить TextView в центре, но не смог поместить его внизу. Может ли кто-нибудь вести меня. вот мой XMLAndroid textview на imageview

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

    <ImageView 
     android:id="@+id/eventimage" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scaleType="fitXY" 
     android:background="#000000"> 
    </ImageView> 

    <TextView 
      android:id="@+id/text98" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:layout_centerVertical="true"    
      android:singleLine="true" 
      android:textColor="@color/white"   
      android:text="LAST" 
      android:textStyle="bold" 
      android:textSize="18sp"/> 
</RelativeLayout> 
+0

добавить это для TextView 'андроида: layout_alignBottom = "@ + id/eventimage" ' – Raghunandan

ответ

2

на TextView использовать следующие атрибуты android:layout_centerHorizontal="true" вместо android:layout_centerVertical="true" и добавить android:alignParentBottom=true". Кроме того, посмотрите на соответствующие варианты расположения, чтобы понять, как с ним работать.

+0

спасибо. Как я могу использовать android: layout_marginBottom независимо от всех экранов? – Vidya

+0

Что вы имеете в виду независимо от всех экранов, вы можете использовать dp, если вы имеете в виду плотность экрана. – bogdan

+0

Как и я хочу разместить textView 20% снизу на всех размерах экрана. Как мне это достичь? Я не могу просто дать номер. – Vidya

1

попробовать

<TextView 
     android:layout_alignParentBottom="true" 
... 
1

Вы можете попробовать использовать что-то вроде

android:layout_alignBaseline (@id/eventimage); 

и добавить отступы на дно позже

1

android:layout_alignParentBottom, чтобы переместить элемент управления в нижней части экрана.

1

Попробуйте следующее:

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

    <ImageView 
     android:id="@+id/eventimage" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     android:background="#000000"> 
    </ImageView> 

    <TextView 
      android:id="@+id/text98" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true"   
      android:singleLine="true" 
      android:textColor="@color/white"   
      android:text="LAST" 
      android:textStyle="bold" 
      android:textSize="18sp"/> 
</RelativeLayout> 
1

Вы можете использовать этот

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

     <ImageView 
      android:id="@+id/eventimage" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:scaleType="fitXY" 
      android:background="#000000"> 
     </ImageView> 

     <TextView 
       android:id="@+id/text98" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:gravity="center_horizontal"    
       android:singleLine="true" 
       android:textColor="@color/white"   
       android:text="LAST" 
       android:layout_alignParentBottom="true" 
       android:textStyle="bold" 
       android:textSize="18sp"/> 
    </RelativeLayout> 
1

Добавьте это в TextView:

android:layout_alignBottom="@id/eventimage" 
1

Используйте этот код:

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

    <ImageView 
     android:id="@+id/eventimage" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scaleType="fitXY" 
     android:background="#000000"> 
    </ImageView> 

    <TextView 
     android:id="@+id/text98" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:layout_alignParentBottom="true" 
     android:alignBottom="@+id/eventimage"    
     android:singleLine="true" 
     android:textColor="@color/white"   
     android:text="LAST" 
     android:textStyle="bold" 
     android:textSize="18sp"/> 
</RelativeLayout> 

Надеюсь, это вам поможет.

1

Этот макет работает в соответствии с вашим требованием .by установки тяжести нижней линейной компоновки, ее вид chilld автоматически выравниваются в Центрально- нижнем положении

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/back" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
     android:background="@drawable/ic_launcher" 
     android:gravity="bottom"> 


    <TextView 
     android:id="@+id/text98" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:gravity="center" 
     android:singleLine="true" 
     android:text="LAST" 
     android:textSize="18sp" 
     android:textStyle="bold" 
     android:textColor="@android:color/white"/ 
     > 

</LinearLayout>