Setting a background image to a view stretches my

2019-01-14 11:01发布

I created a background image bitmap for a view and now the view is being stretched to the size of the background image....

is this normal?

<?xml version="1.0" encoding="utf-8"?>
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/green"
        android:tileMode="repeat"/>

here's how I apply it to my view

v.setBackgroundResource(R.drawable.backgroundgreen);

for instance...

if the image is 500px in height and the view is 200px in height(being set wrap_content as height) after setting the image as background my view becomes 500px in height...

7条回答
Viruses.
2楼-- · 2019-01-14 11:34

I suggest to create a wrapper layout and put the background image in there. i'm using it that way and fits very nicely. see example below

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/settingstab_scroll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="vertical"
    android:background="@drawable/wareninja_wallpaper_img"
    >
<!-- your layouts and components goes here -->
</ScrollView>


...
Social Coding @ AspiroTV

查看更多
登录 后发表回答