0
votes

I am making app with Android Studio and want to auto set width and height of image that I am showing on front page. my code is like this

 <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

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

        <TextView
            android:id="@+id/textView"
            android:layout_width="375dp"
            android:layout_height="220dp"
            android:layout_marginBottom="5sp"
            android:adjustViewBounds="true"
            android:background="@drawable/japuji"
            android:clickable="true"
            android:focusable="true"
            android:linksClickable="true"
            android:scaleType="fitXY"
            android:textStyle="bold" />

this is the scrollview and when i set fill_parent, wrap_content in TextView its not working either, when i test it on big screen images are small ,

i have tried all like changing width to fill_parent and wrap_content

2
There's no image in the code you posted, so we have no idea what's going wrong. Unless you mean the TextView, in which case why are you using a TextView to display an image instead of an ImageView? There are things like scaleType that only work on ImageViews. - Gabe Sechan
"i have tried all like changing width to fill_parent and wrap_content" Changing width of which element? - LarsH

2 Answers

2
votes

You should not display an image as a background of a view, instead, you should use ImageView

    <ImageView
        android:contentDescription="@string/imagedesc"
        android:id="@+id/my_image"

        android:src="@drawable/your_image" 

        android:scaleType="fitCenter"

        android:adjustViewBounds="true"

        android:layout_width="wrap_content"
        android:layout_height="match_parent"
       />

src : sets the image drawable

scaleType : sets the desired scale type, in this case fitCenter with adjustViewBounds set to true and width or height (one of them) to wrap_content will show the full image.

EDIT : if you have a fixed view size and you want to cover it all with that image drawable, you should use centerCrop as a scaleType instead of fitCenter

0
votes

You're apparently displaying the image (android:background="@drawable/japuji") in the TextView, but the TextView has its height and width hard-coded: android:layout_width="375dp" android:layout_height="220dp"

Instead set the TextView's height and width to match_parent.