2015-08-14 4 views
4

Вот мой код XML файлAndroid значок на кнопке

<?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" 
    android:background="#F8F8F8"> 

    <RelativeLayout 
     android:id="@+id/relative_buttons" 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:layout_centerHorizontal="true" 
     android:layout_marginLeft="@dimen/dp_10" 
     android:layout_marginRight="@dimen/dp_10" 
     android:layout_marginTop="@dimen/dp_5" 
     android:gravity="center" 
     android:orientation="horizontal"> 

     <com.hyper.barcodeapp.customClass.CustomButton 
      android:id="@+id/btn_home" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@drawable/home_sel" 
      android:text="@string/home" 
      android:textAllCaps="false" 
      android:textColor="@android:color/white" 
      android:textSize="@dimen/sp_16" /> 


     <FrameLayout 
      android:id="@+id/frame" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/btn_home" 
      android:layout_weight="1"> 

      <com.hyper.barcodeapp.customClass.CustomButton 
       android:id="@+id/btn_promotions" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 

       android:layout_weight="1" 
       android:background="@drawable/promo" 
       android:text="@string/promotions" 
       android:textAllCaps="false" 
       android:textColor="@android:color/tab_indicator_text" 
       android:textSize="@dimen/sp_16" /> 

      <TextView 
       android:id="@+id/txt_badge" 
       android:layout_width="15dp" 
       android:layout_height="15dp" 
       android:layout_alignRight="@id/btn_promotions" 
       android:layout_alignTop="@id/btn_promotions" 
       android:layout_gravity="top|right" 
       android:layout_marginRight="@dimen/dp_1" 
       android:layout_marginTop="@dimen/dp_1" 
       android:background="@drawable/badge_circle" 
       android:gravity="center" 
       android:padding="@dimen/dp_3" 
       android:text="10" 
       android:textSize="5sp" /> 

     </FrameLayout> 


     <com.hyper.barcodeapp.customClass.CustomButton 
      android:id="@+id/btn_search_code" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/frame" 
      android:layout_weight="1" 
      android:background="@drawable/search" 
      android:text="@string/search_code" 
      android:textAllCaps="false" 
      android:textColor="@android:color/tab_indicator_text" 
      android:textSize="@dimen/sp_16" /> 


    </RelativeLayout> 

    <FrameLayout 
     android:id="@+id/child_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/relative_buttons" 
     android:layout_marginTop="@dimen/dp_5" 
     android:layout_weight="8"> 

    </FrameLayout> 
</RelativeLayout> 

Посмотрите на код ясно, что если «txt_badge» есть кнопка, я могу видеть знак как значок на «btn_promotions», но если я использую TextView вместо кнопки «txt_badge» не отображается в макете, что может быть проблемой?

Вот код badge_circle

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <corners android:radius="10dip" /> 
    <solid android:color="@color/tab_button_text_color_not_clicked" /> 
    <stroke 
     android:width="1dip" 
     android:color="#FFF" /> 
    <padding 
     android:bottom="5dip" 
     android:left="5dip" 
     android:right="5dip" 
     android:top="5dip" /> 
</shape> 

ответ

0

Положите два на LinearLayout. Framelayout может иметь только 1 childview

<FrameLayout 
     android:id="@+id/frame" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/btn_home" 
     android:layout_weight="1"> 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

     <com.hyper.barcodeapp.customClass.CustomButton 
      android:id="@+id/btn_promotions" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 

      android:layout_weight="1" 
      android:background="@drawable/promo" 
      android:text="@string/promotions" 
      android:textAllCaps="false" 
      android:textColor="@android:color/tab_indicator_text" 
      android:textSize="@dimen/sp_16" /> 

     <TextView 
      android:id="@+id/txt_badge" 
      android:layout_width="15dp" 
      android:layout_height="15dp" 
      android:layout_alignRight="@id/btn_promotions" 
      android:layout_alignTop="@id/btn_promotions" 
      android:layout_gravity="top|right" 
      android:layout_marginRight="@dimen/dp_1" 
      android:layout_marginTop="@dimen/dp_1" 
      android:background="@drawable/badge_circle" 
      android:gravity="center" 
      android:padding="@dimen/dp_3" 
      android:text="10" 
      android:textSize="5sp" /> 

</RelativeLayout> 

    </FrameLayout> 
+0

С линейным расположением я не могу поставить «txt_badge» в верхнем правом углу «btn_promotions». –

+0

Ow, RelativeLayout w8 – Sheychan

+0

Теперь попробуйте этот RelativeLayout – Sheychan