2017-02-08 2 views
0

GridLayoutに問題があります。以下のレイアウトでは、phone_imageとvoip_imageが重なっていて、私はそれらを望んでいません。 phone_imageは、列0にあり、2ImageButtonsはGridLayoutでオーバーラップしますが、これは不要です

SSCCEはGithubの上欄に https://github.com/emnrd-ito/LayoutDemo

<HorizontalScrollView 
    android:id="@+id/container_scroll_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <GridLayout xmlns:mapbox="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/individual_gridlayout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:alignmentMode="alignBounds" 
     android:columnCount="4" 
     android:columnOrderPreserved="false" 
     android:rowCount="7"> 

     <ImageView 
      android:id="@+id/division_logo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="0" 
      android:layout_columnSpan="3" 
      android:layout_margin="10dp" 
      android:layout_row="0" 
      android:layout_rowSpan="3" 
      android:background="@null" 
      android:layout_gravity="center_horizontal" 
      android:src="@mipmap/ic_launcher" /> 

     <TextView 
      android:id="@+id/employee_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_column="3" 
      android:layout_margin="10dp" 
      android:layout_row="0" 
      android:text="Nobody Lastname" 
      tools:text="name" /> 

     <TextView 
      android:id="@+id/division" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="3" 
      android:layout_margin="10dp" 
      android:layout_row="1" 
      android:text="My Division" 
      tools:text="division" /> 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="3" 
      android:layout_margin="10dp" 
      android:layout_row="2" 
      android:text="My Title" 
      tools:text="position" /> 

     <TextView 
      android:id="@+id/address" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="3" 
      android:layout_margin="10dp" 
      android:layout_row="3" 
      android:text="123 Sesame St." 
      tools:text="address" /> 

     <TextView 
      android:id="@+id/city_state" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="3" 
      android:layout_margin="10dp" 
      android:layout_row="4" 
      android:text="mycity, mystate" 
      tools:text="city,state" /> 

     <TextView 
      android:id="@+id/phone_number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="3" 
      android:layout_margin="10dp" 
      android:layout_row="5" 
      android:text="(555) 555-5555" 
      tools:text="phone" /> 

     <TextView 
      android:id="@+id/email" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="1" 
      android:layout_columnSpan="3" 
      android:layout_margin="10dp" 
      android:layout_row="6" 
      android:text="[email protected]" 
      tools:text="email" /> 


     <ImageButton 
      android:id="@+id/directions_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="0" 
      android:layout_row="4" 
      android:background="@null" 
      android:src="@drawable/ic_directions_enabled" /> 

     <ImageButton 
      android:id="@+id/phone_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="0" 
      android:layout_row="5" 
      android:background="@null" 
      android:src="@drawable/ic_phone_enabled" /> 

     <ImageButton 
      android:id="@+id/voip_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="2" 
      android:layout_row="5" 
      android:background="@null" 
      android:src="@drawable/ic_voip_enabled" /> 

     <ImageButton 
      android:id="@+id/email_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="0" 
      android:layout_row="6" 
      android:background="@null" 
      android:src="@drawable/ic_email_enabled" /> 

    </GridLayout> 
</HorizontalScrollView> 

編集voip_imageです:私はそうのようなSpaceを使用してみました

<android.support.v4.widget.Space 
android:layout_width="match_parent" 
android:layout_height="0dp" 
android:layout_weight="1" 
android:layout_column="1" 
android:layout_row="5"/> 

空白のイメージを使用すると、列全体が挿入されるのに対し、約1/2の列が挿入されているようです。しかし、Spaceコンポーネント内で再生するパラメータがあるかもしれません。

答えて

0

一つの解決策は白紙画像を作成して、描画可能なフォルダにそれを置くことです助けることができます。私は、あなたは、単にこのようvoip_imagelayout_columnプロパティを変更することができ、あなたの問題を解決すると思います。 それで、レイアウトのスペースをこう使いましょう:

<ImageButton 
    android:id="@+id/phone_image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_column="0" 
    android:layout_row="5" 
    android:background="@null" 
    android:src="@drawable/ic_phone_enabled" /> 

<ImageButton 
    android:id="@+id/blank_image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_column="1" 
    android:layout_row="5" 
    android:background="@null" 
    android:src="@drawable/ic_blank" /> 

<ImageButton 
    android:id="@+id/voip_image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_column="2" 
    android:layout_row="5" 
    android:background="@null" 
    android:src="@drawable/ic_voip_enabled" /> 
+1

サイドコメントとして、別のImageButtonの代わりに 'Space'ビューを使うことができます:' android.support.v4.widget.Space'。確かに、この目的で正確に発明されました:https://developer.android.com/reference/android/widget/Space.html –

+1

私は 'スペース'について知らなかった、それを指摘してくれてありがとう。私はそれを本当に素早く試して、実際には2つのアイコンを分離します。それは約1/2の列を挿入するようだが、空のイメージを使用すると列全体が挿入される。しかし、 'Space'コンポーネントで再生するパラメータがあるかもしれません。したがって、質問に追加情報。 –

0

あなたはこのように、両方のvoipImagephoneImageImageButton秒にandroid:maxWidth性を付与しようとすることができます:

<ImageButton 
    android:id="@+id/phone_image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_column="0" 
    android:layout_row="5" 
    android:maxWidth="96dp" 
    android:background="@null" 
    android:src="@drawable/ic_phone_enabled" /> 

<ImageButton 
    android:id="@+id/voip_image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_column="2" 
    android:layout_row="5" 
    android:maxWidth="96dp" 
    android:background="@null" 
    android:src="@drawable/ic_voip_enabled" /> 

更新

上記の変更は必要ありません。

android:layout_column="1" 

希望これは

+1

あなたの返信ありがとうございます。どちらの提案も機能しません。 'maxwidth'を設定することは効果がなく、より現実的な例では、画像のサイズは画面の密度によって変化します。 'layout_column'を1に設定すると、実際には は2つのアイコンを区切りますが、voip_imageとその右側のテキストが重なってしまいます。 –

+0

私は、maxWidth(maxHeight)プロパティを設定すると、レイアウト全体に問題を引き起こす可能性のあるイメージの展開を制限するという利点があると思います(現実的な例)。しかし、あなたが正しいです、私が提案したことは、一般的な問題を解決しません。 –

関連する問題