Как динамически изменить размер изображения на основе высоты содержимого родительского макета?

У меня есть родительский макет с android:layout_height="wrap_content" и в моем коде класса это должно установить фон макета от определенного изображения, но высота изображения больше, чем высота контента. Я хотел изменить размер изображения фона до высоты содержимого родительского макета. Как я могу это сделать?

Черный - родительский макет

Зеленый - содержимое макета

Коричневый - Макет фона (из прорисовки)

Вот как я устанавливаю свой родительский макет фона:view.setBackgroundDrawable(getResources().getDrawable(R.drawable.brown));

РЕДАКТИРОВАТЬ:

Вот мой XML:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<ImageView
    android:id="@+id/item_bg"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:adjustViewBounds="true"
    android:src="@android:color/transparent"
    android:translationX="-10dp" />

<LinearLayout
    android:id="@+id/item_song"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#b97a57"
    android:orientation="horizontal"
    android:padding="5dip" >

    <!-- ListRow Left sied Thumbnail image -->

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dip"
        android:layout_weight="0"
        android:background="@color/aqua"
        android:padding="1dip" >

        <ImageView
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:src="@color/gray" />

        <!-- Thumbnail Progressbar -->

        <ProgressBar
            android:id="@+id/progressbar"
            style="?android:attr/progressBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />
    </RelativeLayout>
</LinearLayout></FrameLayout>

и мой, где я называю это расположение в моем слушателе класса Java:

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    view.setBackgroundDrawable(getResources().getDrawable(R.drawable.list_item_selected));
     }

Именно здесь я имел в виду, что я не могу получить ссылку на сам ImageView, потому что я могу иметь только View view от onItemClick, Это ListView, и я хотел изменить фон при нажатии.

В любом случае, как я могу изменить размер содержимого, чтобы высота фона (коричневого) fill родительский макет (зеленый)?

0 ответов

Другие вопросы по тегам