2015-11-05 75 views
-1

我正在使用RelativeLayout在我們的xml中顯示帶有TextView(count)的carticon。TextView隱藏在按鈕後面

代碼:

<android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/toolbar" 
android:minHeight="?attr/actionBarSize" 
android:background="@color/primary" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <Button 
     android:layout_width="65dip" 
     android:layout_height="65dip" 
     android:id="@+id/showevents" 
     android:layout_gravity="right" 
     android:textSize="12sp" 
     android:background="@drawable/cart" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_margin="0dp" 
     android:textColor="#000000"/> 
    <TextView 
     android:id="@+id/textOne" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/showevents" 
     android:layout_alignRight="@id/showevents" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="5dp" 
     android:paddingBottom="1dp" 
     android:paddingLeft="4dp" 
     android:paddingRight="4dp" 
     android:text="" 
     android:textColor="#FFF" 
     android:textSize="16sp" 
     android:textStyle="bold" 
     android:background="@drawable/badge_circle"/> 
</RelativeLayout> 

我怎麼能顯示的TextView(在右側)就在按鈕上方? 現在我們的TextView顯示在購物車圖標後面。
任何幫助,將不勝感激

+0

包括截圖和你嘗試過什麼到目前爲止,將有助於解釋。 – Shlublu

回答

0
更換 android:layout_alignTop="@id/showevents"

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

    <TextView 
      android:id="@+id/textOne" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignTop="@id/showevents" 
      android:layout_alignRight="@id/showevents" 
      android:layout_marginRight="5dp" 
      android:layout_gravity="right" 
      android:background="@drawable/badge_circle" 
      android:layout_marginTop="5dp" 
      android:paddingBottom="1dp" 
      android:paddingLeft="4dp" 
      android:paddingRight="4dp" 
      android:text="" 
      android:textColor="#FFF" 
      android:textSize="16sp" 
      android:textStyle="bold"/> 
    <Button 
      android:layout_width="65dip" 
      android:layout_height="65dip" 
      android:id="@+id/showevents" 
      android:layout_gravity="right" 
      android:textSize="12sp" 
      android:background="@drawable/cart" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_margin="0dp" 
      android:textColor="#000000"/> 
</LinearLayout> 

0

我想這way..and它顯示了完美

<RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/carticon" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="10dp" 
      android:id="@+id/relcarts" 
      android:layout_gravity="right" 
      android:layout_alignParentRight="true"> 

      <TextView 
       android:layout_width="19dp" 
       android:layout_height="wrap_content" 
       android:background="@drawable/cart_counter_bg" 
       android:text="0" 
       android:id="@+id/cartcountrs" 
       android:textColor="@android:color/white" 
       android:gravity="center_vertical|center_horizontal" 
       android:layout_marginLeft="15dp" 
       /> 
     </RelativeLayout> 
0

試試這個方法:

<android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/toolbar" 
android:minHeight="?attr/actionBarSize" 
android:background="@color/primary" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    > 
    <Button 
     android:layout_width="65dip" 
     android:layout_height="65dip" 
     android:id="@+id/showevents" 
     android:layout_gravity="right" 
     android:textSize="12sp" 
     android:background="@drawable/cart" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_margin="0dp" 
     android:textColor="#000000" 
    /> 
    <TextView 
     android:id="@+id/textOne" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/showevents" 
     android:layout_alignRight="@id/showevents" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="5dp" 
     android:paddingBottom="1dp" 
     android:paddingLeft="4dp" 
     android:paddingRight="4dp" 
     android:text="" 
     android:textColor="#FFF" 
     android:textSize="16sp" 
     android:textStyle="bold" 
     android:background="@drawable/badge_circle" 
    /> 
</RelativeLayout> 

我簡單地android:layout_above="@id/showevents"