2014-06-30 2 views
1

Я только что начал программирование на Android. Я писал xml в RelativeLayout и обнаружил, что атрибут gravity не работает. Каждый элемент в макете перекрывает друг друга. Я знаю, что могут быть лучшие способы позиционирования, но мне любопытно узнать, что это такое, что я не делаю правильно? Пожалуйста, помогите мнеатрибут тяжести на android xml не работает

 <?xml version="1.0" encoding="utf-8"?> 
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 
      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/message" 
       android:gravity="start" 
      /> 

      <Button 
       android:id="@+id/btnclose" 
       android:textColor="#ffffff" 
       android:background="#780956" 
       android:textSize="18sp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="close" 
       android:text="close" 
       android:gravity="bottom" 
     /> 
    <Button 
     android:id="@+id/btnclick" 
     android:textColor="#ffffff" 
     android:background="#123456" 
     android:textSize="18sp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="close" 
     android:text="click" 
     android:gravity="center" 
     /> 
</RelativeLayout> 

ответ

1

не просто использовать тяжести

есть два типа их тяжести, расположение гравитации

один влияет на все элементы и другие не

попробовать оба из них ..

0

Как вы используете RelativeLayout, правильный способ расположить вид на использовании ниже атрибутов:

  1. андроида: centerInParent
  2. андроида: layout_toLeftOf
  3. андроида: layout_toRightOf
  4. android: layoutBelow

Подробнее о Positing Views.

0

Поскольку вы используете RelativeLayout, задайте свойства следующим образом:

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

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="message" /> 

    <Button 
     android:id="@+id/btnclose" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:background="#780956" 
     android:onClick="close" 
     android:text="close" 
     android:textColor="#ffffff" 
     android:textSize="18sp" /> 

    <Button 
     android:id="@+id/btnclick" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#123456" 
     android:layout_centerInParent="true" 
     android:onClick="close" 
     android:text="click" 
     android:textColor="#ffffff" 
     android:textSize="18sp" /> 


</RelativeLayout> 
Смежные вопросы