2017-10-04 10 views
-1

Button、TextView、ImageView(質問記号付き)で簡単なレイアウトを作成しました。 ImageViewをボタンの右端に揃えるにはどうすればよいですか?

The question mark should be a bit more right

enter image description here

<Button 
     android:background="#f00" 
     android:textSize="25dp" 
     android:layout_width="200dp" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:text="Button" 
     android:id="@+id/button" /> 


    <TextView 
     android:id="@+id/textViewmas" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/button" 
     android:layout_alignLeft="@+id/button" 
     android:layout_alignStart="@+id/button" 
     android:text="title " 
     android:textSize="18dp" /> 

    <ImageView 
     android:id="@+id/questionmark" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@id/textViewmas" 
     android:layout_alignTop="@+id/textViewmas" 
     android:layout_alignRight="@+id/button" 
     android:layout_alignEnd="@+id/button" 
     app:srcCompat="@drawable/questionmark"/> 

私は、ボタンの右端に揃えるために、画像の右端(questionmarkを)したいです。 追加の上下は、タイトルのtextView(同じ高さ)の上下に揃えます。

画像が右端で整列しないが、もう少し左に整列されないのはなぜですか? タイトルのテキストサイズを大きくすると(たとえば30dp)、問題は消えますが、小さなテキストサイズが必要になることに気付きました。

------ EDIT:イメージの最小サイズはおそらく、文がうまくいきませんか?

android:layout_alignRight="@+id/button" 

か::

+0

の終わりに縮小画像を移動するためにandroid:scaleType="fitEnd"を使用することですペイントしたい場合は、私はあなたのためにデザインします。 –

+0

画像に余分な余白がないことを確認してください。イメージに余分な余白がある場合は、Photoshopまたは他のツールを使用して削除します。または、この画像で確認し、適合するかどうかを確認してください。 https://image.flaticon.com/icons/png/512/78/78299.png – Aveek

+0

解決策を掲載しました。 –

答えて

1

これはImageView

enter image description here

あなたandroid:layout_alignTop="@+id/textViewmas"属性なしでどのように表示されるかは、あなたのImageView

<Button 
    android:id="@+id/button" 
    android:layout_height="wrap_content" 
    android:layout_width="200dp" 
    android:textSize="25dp" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:background="#f00" 
    android:text="Button"/> 

<TextView 
    android:id="@+id/textViewmas" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/button" 
    android:layout_alignLeft="@+id/button" 
    android:text="title " 
    android:textSize="18dp" /> 

<ImageView 
    android:id="@+id/questionmark" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@id/textViewmas" 
    android:layout_alignTop="@+id/textViewmas" 
    android:layout_alignRight="@+id/button" 
    android:layout_alignEnd="@+id/button" 
    android:scaleType="fitEnd" 
    app:srcCompat="@mipmap/ic_launcher"/> 

説明

android:scaleType="fitEnd"を追加dd layout_alignTopの属性がImageViewに設定されている場合、それはTextViewの高さまで絞られ、それに含まれるイメージは縮小されます。既定では、ImageViewscaleTypeプロパティはcenterInsideと表示されます。画像を縮小して画像ビューの中心に揃えることで、左右にいくらかのスペースを追加します。

ソリューションは、uは画像を作ることができますどのようなuはまさに望んでいるイメージ図

出力

enter image description here

+0

ありがとうございました。 – user7940193

0

を使用でき

android:layout_alignEnd="@+id/button" 

をし、その後、左からある程度のマージンを追加することができます。

+0

あなたのアライメントステートメントの両方が既に自分のコードに追加されていれば教えてください。余白が残っていても何も変わりません。 – user7940193

+0

次に、テキストの高さを取得し、イメージの高さと高さに設定できます。 –

関連する問題