2017-04-17 4 views
0

Ich möchte ein Optionsmenü (3 Punkte) in der rechten Ecke meines CardView hinzufügen. Das Problem ist, dass es hinzugefügt wird, wenn der TextView endet. Ich möchte es rechts mit einem 5dp-Rand rechts von dem Bildschirm hinzufügen.ImageButton auf der rechten Seite des Bildschirms hinzufügen

Irgendwelche Ideen, wie kann ich den ImageButton auf der rechten Seite des Bildschirms in jedem cardview hinzufügen?

 <ImageButton 
      android:id="@+id/imageButton" 
      android:layout_width="20dp" 
      android:layout_height="30dp" 
      android:src="@mipmap/ic_dots_vertical_black_18dp" 
      android:contentDescription="..." 
      android:background="@null" 
      android:visibility="gone" 
      android:layout_gravity="right" /> 

meine volle xml:

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

    <android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     card_view:cardCornerRadius="0dp" 
     android:id="@+id/card_view" 
     android:layout_marginBottom="0dp" 
     android:layout_marginEnd="0dp" 
     android:layout_marginLeft="0dp" 
     android:layout_marginRight="0dp" 
     android:layout_marginStart="0dp" 
     android:layout_marginTop="0dp"> 

     <LinearLayout 
      android:padding="@dimen/activity_horizontal_margin" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:orientation="horizontal" > 

       <ImageView 
        android:layout_width="50dp" 
        android:layout_height="50dp" 
        android:padding="0dp" 
        android:id="@+id/ProfilePic" 
        android:paddingBottom="20dp" 
        android:adjustViewBounds="true" /> 

       <TextView 
        android:id="@+id/textViewUser" 
        android:textStyle="bold" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:paddingLeft="10dp" 
        android:paddingBottom="20dp" 
        /> 

       <ImageButton 
        android:id="@+id/imageButton" 
        android:layout_width="20dp" 
        android:layout_height="30dp" 
        android:src="@mipmap/ic_dots_vertical_black_18dp" 
        android:contentDescription="..." 
        android:background="@null" 
        android:visibility="gone" 
        android:layout_gravity="right" /> 

      </LinearLayout> 
       </LinearLayout> 



    </android.support.v7.widget.CardView> 

</RelativeLayout> 

Antwort

1

Sie ein Gewicht von 1 geben Textview könnte:

android:layout_weight="1" 

oder einfach ein relatives Layout verwenden, um Ihre Links/Rechts-Tasten zu positionieren, dann setzen die Textansicht in der Mitte.

+0

Ihnen danken. und ich muss auch Android entfernen: layout_centerHorizontal = "true", damit es funktioniert. –

0

Sie können dies auch versuchen:

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

    <android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     card_view:cardCornerRadius="0dp" 
     android:id="@+id/card_view" 
     android:layout_marginBottom="0dp" 
     android:layout_marginEnd="0dp" 
     android:layout_marginLeft="0dp" 
     android:layout_marginRight="0dp" 
     android:layout_marginStart="0dp" 
     android:layout_marginTop="0dp"> 

     <RelativeLayout 
      android:padding="@dimen/activity_horizontal_margin" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <ImageView 
       android:layout_width="50dp" 
       android:layout_height="50dp" 
       android:id="@+id/ProfilePic" 
       android:src="@mipmap/ic_launcher"/> 

      <ImageButton 
       android:id="@+id/imageButton" 
       android:layout_width="20dp" 
       android:layout_height="30dp" 
       android:src="@mipmap/ic_launcher" 
       android:contentDescription="..." 
       android:background="@null" 
       android:visibility="visible" 
       android:layout_alignParentRight="true"/> 

      <TextView 
       android:id="@+id/textViewUser" 
       android:textStyle="bold" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/ProfilePic" 
       android:layout_toLeftOf="@id/imageButton" 
       android:paddingLeft="16dp" 
       android:paddingRight="5dp" 
       android:paddingBottom="20dp" 
       android:text="This is a sample text"/> 

     </RelativeLayout> 
    </android.support.v7.widget.CardView> 
</RelativeLayout> 

OUTPUT:

enter image description here

Hope this helfen ~

Verwandte Themen