0

PNG画像であるImageViewとその直下のTextViewを使ってフラグメントを追加しました。 フラグメントがうまく表示されていますが、画面を回転すると画像が画面のほとんどを占め、TextViewが部分的にカットされます。 は、ここでは、コードです:Android、画像とテキストビューを画面に合わせる

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

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

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:layout_below="@id/shopping_cart" 
    android:text="@string/no_data" 
    android:gravity="center"/> 


</RelativeLayout> 

私は画面に画像とテキストの両方を表示するために、画像のサイズを変更する方法を見つけようとしている

答えて

1

ルート要素かのようにスクロールビューを使用してみてください画像のサイズを変更するのではなく、同じ画像サイズを保持したい。

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

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/shopping_text" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:text="@string/no_data"/> 

<ImageView 
    android:id="@+id/shopping_cart" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@id/shopping_text" 
    android:src="@drawable/shopping_cart"/> 


</RelativeLayout> 
+0

実際、それはオプションになる可能性があります。アイデアをありがとう。イメージのサイズを変更できない場合、私はあなたの解決策を使用します – user1341300

0

ここでは、コードです。私はあなたのImageViewのコードでこの属性を使用することを示唆している:

https://developer.android.com/reference/android/widget/ImageView.ScaleType.html

スケールタイプは、あなたのイメージがビューに応じて拡張する方法を定義します。私は一度同様の問題に直面し、私はこれを使用して解決することができました。それを言って、私はあなたが使用しているイメージを見ていないので、私はそれを非常に確信することはできません。しかし、私はあなたが使用すると言うでしょう:

android:scaleType="centerCrop" 

あなたは上記のリンクで属性の定義を見つけることができます。また、私はあなたのアプリのためにどのデバイスをターゲットにしているのかわからないが、スクロールビューの中にビューを保持して、小さな画面でも表示できるようにするのは常に良い。

centerCropではなく、別の属性で試してみてください。

乾杯!

+0

これは動作しません。コードを試してみても画像が正しく整列しない場合 – user1341300

+0

私はあなたの画面全体がimageviewとtextviewだけを含んでいると仮定しており、ImageViewの下にtextViewを置いて、これらの項目を画面の中央に揃えると仮定します。私はこれらすべてを達成することができます。画像をアップロードできたら、試してみることができます。 –

0
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 


<LinearLayout 
    android:id="@+id/text_image_container" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

(Enter view here) 

</LinearLayout> 
0

さてさて、そうまずあなたが全ての濃度でImageViewのためのイメージを持っていることを確認します - ここに小さなスニペットだ

<ScrollView 
    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:fillViewport="true"> 


<RelativeLayout 
    android:id="@+id/container" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

(all your view elements) 

</RelativeLayout> 

関連する問題