2016-12-12 7 views
0

Ich möchte innerhalb der cardview ein Imageview auf der rechten Seite setzen, sondern Ausrichten funktioniert nicht ... mir bitteWie richtet man ein ImageView auf der rechten Seite aus?

Layout-

<FrameLayout 
    android:id="@+id/framelayout" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent"/> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/lin1" 
     android:orientation="vertical"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
     <android.support.v7.widget.CardView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="05dp" 
      android:layout_marginTop="15dp" 
      android:id="@+id/casardviewvisit"> 
       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:background="#482048" 
        android:orientation="horizontal"> 
       <ImageView 
        android:layout_width="wrap_content" 

        android:layout_height="wrap_content" 
        android:src="@drawable/omg"/> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textSize="20dp" 
        android:textColor="#fff" 
        android:textStyle="bold" 
        android:layout_marginLeft="20dp" 
        android:layout_gravity="center" 
        android:text="Add Order"/> 

        <ImageButton 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/sent" 
         android:layout_gravity="right" 
         android:id="@+id/imageButtsdon" /> 
       </LinearLayout> 
     </android.support.v7.widget.CardView> 
    </LinearLayout> 
    </framelayout> 

schlage ich versuche, wie auf diese Weise bin, aber es funktioniert nicht, und ich weiß nicht, warum dies nicht

funktioniert
+1

Sie Textview layout_width = 0DP machen kann gezeigt, layout_weight = 1 ... Sag mir, wenn es für yah funktioniert – Sheychan

+0

yup es funktioniert perfekt thanq so sehr. –

Antwort

0

Gelassen an Ihren Textview gestreckt durch

android:layout_width="0dp" 
android:layout_weight="1" 
0

tun können Sie folgenden Code verwenden.

<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 

    android:layout_height="wrap_content" 
    android:layout_marginLeft="05dp" 
    android:layout_marginTop="15dp" 
    android:id="@+id/casardviewvisit"> 

    <LinearLayout 
     android:weightSum="1" 
     android:gravity="center" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#482048" 
     android:orientation="horizontal"> 
     <ImageView 
      android:layout_weight=".2" 
      android:layout_width="0dp" 
      android:layout_height="50dp" 
      android:src="@drawable/test"/> 
     <TextView 
      android:layout_weight=".5" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:textSize="20dp" 
      android:textColor="#fff" 
      android:textStyle="bold" 
      android:layout_marginLeft="20dp" 
      android:layout_gravity="center" 
      android:text="Add Order"/> 

     <ImageView 
      android:layout_weight=".2" 
      android:layout_width="0dp" 
      android:layout_height="50dp" 
      android:src="@drawable/test" 
      android:layout_gravity="right" 
      android:id="@+id/imageButtsdon" /> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 

Sie können es kopieren und Ihre XML-Datei

0

Verwenden Sie einfach einfache Schwerkraft für die Bildansicht.

<FrameLayout 
    android:id="@+id/framelayout" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/lin1" 
     android:orientation="vertical"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
      <android.support.v7.widget.CardView 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="05dp" 
       android:layout_marginTop="15dp" 
       android:id="@+id/casardviewvisit"> 
       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:background="#482048" 
        android:orientation="horizontal"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textSize="20dp" 
         android:textColor="#fff" 
         android:textStyle="bold" 
         android:layout_marginLeft="20dp" 
         android:layout_gravity="center" 
         android:text="Add Order"/> 

        <ImageButton 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/sent" 
         android:layout_gravity="right" 
         android:id="@+id/imageButtsdon" /> 
       </LinearLayout> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_gravity="end" 
        android:layout_height="match_parent" 
        android:layout_marginRight="16dp" 
        android:src="@drawable/omg"/> 
      </android.support.v7.widget.CardView> 
     </LinearLayout> 
    </LinearLayout> 
</FrameLayout> 
0

Verwenden Sie diesen Code, um Imageview auf der rechten Seite in CardView zu setzen, indem Sie nur das relative Layout verwenden.

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/casardviewvisit" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="05dp" 
      android:layout_marginTop="15dp"> 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="#482048"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_marginLeft="20dp" 
        android:text="Add Order" 
        android:textColor="#fff" 
        android:textSize="20dp" 
        android:textStyle="bold" /> 

       <ImageButton 
        android:id="@+id/imageButtsdon" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="right" /> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_gravity="right" 
        android:src="@drawable/beautiful" /> 
      </RelativeLayout> 
     </android.support.v7.widget.CardView> 
0

Bitte überprüfen Sie folgende xml.

<FrameLayout 
     android:id="@+id/framelayout" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent"/> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/lin1" 
      android:orientation="vertical"> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 
      <android.support.v7.widget.CardView 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="05dp" 
       android:layout_marginTop="15dp" 
       android:id="@+id/casardviewvisit"> 
        <LinearLayout 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:background="#482048" 
         android:orientation="horizontal"> 

        <LinearLayout 
         android:layout_width="0dp" 
         android:layout_height="fill_parent" 
         android:layout_weight="1" 
         android:background="#482048" 
         android:orientation="horizontal"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textSize="20dp" 
         android:textColor="#fff" 
         android:textStyle="bold" 
         android:layout_marginLeft="20dp" 
         android:layout_gravity="center" 
         android:text="Add Order"/> 

        <ImageButton 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:src="@drawable/sent" 
          android:layout_gravity="right" 
          android:id="@+id/imageButtsdon" /> 
        </LinearLayout> 
        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/omg"/> 
        </LinearLayout> 
      </android.support.v7.widget.CardView> 
     </LinearLayout> 
     </framelayout> 
0

Verwenden RelativeLayout statt LinearLayout und

android:layout_alignParentRight="true" 

den ImageView

das ist alles sorgen !!

0

Im Inneren des Cardview, der Behälter nur geben Linearlayout Weightsum von 1 und geben sowohl die Imageviews ein Gewicht von 0,25 und Textview ein Gewicht von 0,5, wie unten

<android.support.v7.widget.CardView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/casardviewvisit" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="05dp" 
      android:layout_marginTop="15dp" > 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="#482048" 
       android:orientation="horizontal" 
       android:weightSum="1" > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight=".25" 
        android:src="@drawable/omg" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_marginLeft="20dp" 
        android:layout_weight=".5" 
        android:text="Add Order" 
        android:textColor="#fff" 
        android:textSize="20dp" 
        android:textStyle="bold" /> 

       <ImageButton 
        android:id="@+id/imageButtsdon" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="right" 
        android:layout_weight=".2" 
        android:src="@drawable/sent" /> 
      </LinearLayout> 
    </android.support.v7.widget.CardView> 
Verwandte Themen