Android:更改包含的xml中的imageview src

问题描述 投票:1回答:1

是否可以从另一个xml更改包含的xml中的imageView src?

[其中包含菜单栏的几幅图像,其中包括:

        <include layout="@layout/panel_settings"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="top">
        </include>

包含看起来像这样:

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

<LinearLayout
    android:id="@+id/linearLayout_icon_panel_right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/background_relativelayout_settings_menu_bar_right"
    android:orientation="vertical"
    android:weightSum="5"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_below="@+id/LinearLayout_titel_panel"
    android:layout_alignBottom="@+id/RelativeLayout_Settings_CenterPanel"
    android:layout_weight="0.86"
    android:baselineAligned="false">

    <ImageView
        android:id="@+id/imageView_settings_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/settings" />

    <ImageView
        android:id="@+id/imageView_settings_contra_con"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/contracon" />

    <ImageView
        android:id="@+id/imageView_settings_error_log"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/errorlog" />

    <ImageView
        android:id="@+id/imageView_settings_reconnect"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/screen" />

    <ImageView
        android:id="@+id/imageView_settings_invis"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/autostart"
        android:visibility="invisible" />
</LinearLayout>

现在,我想通过包含的顶部xml更改android:src标签。那怎么可能?

android xml include imageview
1个回答
0
投票

在包含的布局中创建android.graphics.drawable.Drawable类型的变量。]​​>

然后在include语句中设置drawable。

© www.soinside.com 2019 - 2024. All rights reserved.