2015-08-14 1 views
4

Voici mon code pour le fichier xmlBadge Android sur le bouton

<?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> 

Regardez le code clairement, si « txt_badge » est un bouton je peux voir Badge comme icône « btn_promotions », mais si je l'utilise Textview Au lieu du bouton, "txt_badge" n'est pas montré dans la mise en page, quel peut être le problème?

Voici le code 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> 

Répondre

0

Mettre les deux sur un LinearLayout. Framelayout ne peut avoir qu'une seule vue enfant

<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

Avec une disposition linéaire, je ne peux pas mettre "txt_badge" en haut à droite de "btn_promotions". –

+0

Ow, RelativeLayout w8 – Sheychan

+0

Maintenant, essayez ce RelativeLayout – Sheychan