2017-07-04 12 views
0

線形レイアウトを使用して相対レイアウト内にイメージビューを表示しています。私はすべての画面の種類の間にスペースを入れずに、画像の幅が画面の横幅に占めるように見えるようにします。 しかし、私はまだビューの間に不要なスペースを取得します。私はこれについて助けが必要です。線形レイアウトの項目が画面に正しく適合しない

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/back_main" 
    tools:context="com.example.MainActivity"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="1" 
     android:layout_alignParentBottom="true"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="56dp" 
      android:layout_weight="0.25" 
      android:src="@drawable/img_audio"/> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="56dp" 
      android:layout_weight="0.25" 
      android:src="@drawable/img_event"/> 

     <ImageView 
      android:id="@+id/imageView" 
      android:layout_width="wrap_content" 
      android:layout_height="56dp" 
      android:layout_weight="0.25" 
      android:src="@drawable/img_video" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="56dp" 
      android:layout_weight="0.25" 
      android:src="@drawable/img_more"/> 
    </LinearLayout> 

</RelativeLayout> 
+0

画像を画面の水平方向に配置しますか? –

+0

ええ。それは幅を埋めるdoesntnt – Chukwuma

+0

それはあなたの画像のサイズと画面の幅に対応するためではないはずです。たぶんあなたはプログラムの画面の幅を取得し、画像の数(ハードコーディング)として結果を設定するためにそれを数えることができます。 –

答えて

1

使用:android:scaleType="fitXY"

はたぶん

<ImageView 
     android:layout_width="0dp" 
     android:layout_height="56dp" 
     android:layout_weight="0.25" 
     android:scaleType="fitXY" 
     android:src="@drawable/img_audio"/> 
0

次のレイアウトでimageviewのあなたのコードを交換してください(私はあなたの質問からコードを変更し、ニーズに応じて変更)

トリックを行います
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/back_main" 
tools:context="com.example.MainActivity"> 

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

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="56dp" 
     android:layout_weight="1" 
     android:src="@drawable/foo" /> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="56dp" 
     android:layout_weight="1" 
     android:src="@drawable/bar"/> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="56dp" 
     android:layout_weight="1" 
     android:src="@drawable/foobar"/> 

</LinearLayout> 

使用している画像によっては、ImageViewsで「android:scaleType」を使用することを検討してください。

関連する問題