2017-05-16 4 views
0

青いアイコンをカードの中央に正確に配置しようとしていますが、何らかの理由でアイコンがカードの上に上がります。 誰かが間違っていることを教えてもらえますか? おかげで、親の中心にイメージビューがありません - Android

ここに私の問題のスクリーンショットです:

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> 

答えて

0

私はGridViewの項目であなたの親はあなたから見ることができないのLinearLayoutであることを前提としていコードスニペット。その場合は、でframeLayoutのプロパティでwrap_contentする高さを設定

<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

指定されたコードスニペットは、親としてLinearLayoutで正常に動作しています。

<?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を削除し、子RelativeLayoutにそのattributesを追加します。

2.ImageViewimageを設定する代わりにapp:srcCompatの使用attribute android:src。あなたは自分のCardViewLinearLayoutの下に入れ、その後、コンテナとしてCardViewを使用している場合は、

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

はこれを試してみてください。

OUTPUT:

enter image description here

関連する問題