2013-04-26 7 views
2

как я могу наложить Button над другим внутри RelativeLayout?андроид - перекрытие кнопки над другим

Example

Спасибо.

Вот что я пробовал. Спасибо

<RelativeLayout 
     android:id="@+id/category" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_gravity="center_vertical|center_horizontal|center" 
     android:gravity="center" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/btn1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignTop="@id/btn2" 
      android:layout_centerHorizontal="true" 
      android:layout_centerInParent="true" 
      android:layout_centerVertical="true" 
      android:src="@drawable/btn1" /> 

     <ImageView 
      android:id="@+id/btn2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/btn2" /> 

    </RelativeLayout> 
+0

вы можете попробовать добавить к btn2 отрицательный левый край – Blackbelt

+1

Вы можете дать запас ко второму, а также применять to_rightof собственности на второй на основе первого. – Noundla

ответ

6

Вы можете сделать это, установив маржу в отрицательное значение.

<?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="wrap_content"> 
      <ImageView android:id="@+id/btn1" 
       android:layout_width="100dp" 
       android:layout_height="50dp"/> 
      <ImageView android:layout_width="100dp" 
       android:layout_height="50dp" 
       android:layout_toRightOf="@id/btn1" 
       android:layout_marginLeft="-20dp"/> 
     </RelativeLayout> 
+0

Спасибо. работал как шарм – dracula

2

вот как вы можете это достичь. использовать атрибут layout_margin для кнопки справа и дать отрицательное значение.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/category" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" > 

<Button 
    android:id="@+id/btn1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="MyLargeBtn" /> 

<Button 
    android:id="@+id/btn2" 
    android:layout_toRightOf="@id/btn1" 
    android:layout_marginLeft="-10dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="SmallBtn" /> 

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