2017-05-16 5 views
0

Ich versuche, das blaue Symbol genau in der Mitte der Karte zu positionieren, aber aus irgendeinem Grund geht das Symbol an die Spitze der Karte. Kann mir jemand sagen, was los ist? Danke,Bildansicht nicht zentriert in Eltern - Android

Hier ist ein Screenshot von meinem Problem:

enter image description here

<GridView 
android:id="@+id/documents_grid" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_marginTop="10dp" 
android:columnWidth="@dimen/document_grid_item_width" 
android:gravity="center" 
android:horizontalSpacing="0dp" 
android:numColumns="auto_fit" 
android:stretchMode="spacingWidthUniform" 
android:verticalSpacing="48dp" /> 
<?xml version="1.0" encoding="utf-8"?> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.9" 
    android:focusable="true" 
    android:foreground="?android:selectableItemBackground" 
    android:background="@drawable/document_grid_item_bg"> 

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

     <ImageView 
      android:id="@+id/draft_more_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginTop="5dp" 
      app:srcCompat="@drawable/ic_more" /> 

     <ImageView 
      android:id="@+id/imageView5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      app:srcCompat="@drawable/draft_icon" /> 

    </RelativeLayout> 
</FrameLayout> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_margin="5dp" 
    android:layout_weight="0.1"> 

    <TextView 
     android:id="@+id/draft_date_tv" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:text="Date" /> 
</RelativeLayout> 

Antwort

0

Ich gehe davon aus, dass in gridview Artikel Ihre Eltern Linearlayout ist, die nicht aus gesehen werden können, Ihre Code-Auszug. Wenn das der Fall ist, setzen Sie in FrameLayout Eigenschaften die Höhe

<FrameLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_weight="0.9" 
android:focusable="true" 
android:foreground="?android:selectableItemBackground" 
android:background="@drawable/document_grid_item_bg"> 
0

Da Code-Schnipsel wrap_content arbeitet mit LinearLayout als Eltern in Ordnung.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_height="wrap_content"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.9" 
     android:focusable="true" 
     android:background="@color/colorGreen" 
     android:foreground="?android:selectableItemBackground"> 

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

      <ImageView 
       android:id="@+id/draft_more_button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentTop="true" 
       android:layout_marginTop="5dp" 
       app:srcCompat="@drawable/ic_more" /> 

      <ImageView 
       android:id="@+id/imageView5" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       app:srcCompat="@drawable/draft_icon" 
       android:layout_centerInParent="true" /> 

     </RelativeLayout> 
    </FrameLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_margin="5dp" 
     android:layout_weight="0.1"> 

     <TextView 
      android:id="@+id/draft_date_tv" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:text="Date" /> 
    </RelativeLayout> 

</LinearLayout> 
0

1.FrameLayout entfernen und fügen Sie seine attributes zu Kind RelativeLayout.

2. Verwenden attribute android:src statt app:srcCompatimage auf ImageView einzustellen.

Versuchen Sie folgendes:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.9" 
     android:background="#fff"> 

     <ImageView 
      android:id="@+id/draft_more_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginTop="5dp" 
      android:layout_marginRight="5dp" 
      android:src="@drawable/ic_more" /> 

     <ImageView 
      android:id="@+id/imageView5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:src="@drawable/draft_icon" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_margin="5dp" 
     android:layout_weight="0.1"> 

     <TextView 
      android:id="@+id/draft_date_tv" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:text="16 May 2017" /> 
    </RelativeLayout> 

</LinearLayout> 

FYI, Wenn Sie CardView als Container verwenden, dann setzen Sie einfach unten LinearLayout in Ihrem CardView.

OUTPUT:

enter image description here