设置图像动态时,图像未显示在imageview中

时间:2017-12-08 13:40:13

标签: android imageview

这里是我的布局,我设置了一个静态图像并且显示成功,但是当我设置动态时,它不会更新之前的图像。这是我的imageview edit_profile_civ_profile_image          

    <include layout="@layout/content_edit_profile" />

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:contentInsetStart="0dp">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:contentInsetStart="0dp"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:titleEnabled="false">

            <RelativeLayout
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/orange_1">

                <TextView
                    android:id="@+id/profile_tv_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="@dimen/_15sdp"
                    android:gravity="center"
                    android:text="@string/profile"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/_16sdp" />

                <android.support.design.widget.CoordinatorLayout
                    android:id="@+id/profile_iv_image"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/profile_tv_title"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="@dimen/_30sdp">

                    <de.hdodenhof.circleimageview.CircleImageView
                        android:id="@+id/edit_profile_civ_profile_image"
                        android:layout_width="@dimen/_80sdp"
                        android:layout_height="@dimen/_80sdp"
                        android:src="@mipmap/selected"
                        app:civ_border_color="@color/orange_1"
                        app:civ_border_width="@dimen/_2sdp" />

                    <android.support.design.widget.FloatingActionButton
                        android:id="@+id/edtProfile"
                        android:layout_width="@dimen/_25sdp"
                        android:layout_height="@dimen/_25sdp"
                        android:src="@mipmap/ic_camera_orange"
                        app:backgroundTint="@android:color/white"
                        app:fabSize="mini"
                        app:layout_anchor="@id/edit_profile_civ_profile_image"
                        app:layout_anchorGravity="bottom|right|end" />

                </android.support.design.widget.CoordinatorLayout>

                <de.hdodenhof.circleimageview.CircleImageView
                    android:layout_width="@dimen/_110sdp"
                    android:layout_height="@dimen/_110sdp"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center_horizontal"
                    android:src="@mipmap/ic_welcome_1"
                    android:visibility="gone"
                    app:civ_border_color="@color/green_1"
                    app:civ_border_width="@dimen/_6sdp" />

                <TextView
                    android:id="@+id/profile_tv_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/profile_iv_image"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="@dimen/_15sdp"
                    android:gravity="center_horizontal"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/_20sdp"
                    tools:text="Abd al Hakim" />

                <TextView
                    android:id="@+id/profile_tv_gender"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/profile_tv_name"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="@dimen/_2sdp"
                    android:gravity="center_horizontal"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/_12sdp"
                    android:visibility="gone"
                    tools:text="Male" />

                <TextView
                    android:id="@+id/profile_tv_mobile_number"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/profile_tv_gender"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="@dimen/_8sdp"
                    android:drawablePadding="@dimen/_10sdp"
                    android:drawableStart="@mipmap/ic_call_white"
                    android:gravity="center_vertical"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/_10sdp"
                    tools:text="+1244-45785621" />

                <TextView
                    android:id="@+id/profile_tv_email"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/profile_tv_mobile_number"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginBottom="@dimen/_15sdp"
                    android:layout_marginTop="@dimen/_8sdp"
                    android:drawablePadding="@dimen/_10sdp"
                    android:drawableStart="@mipmap/ic_email"
                    android:gravity="center_vertical"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/_10sdp"
                    tools:text="alhakim0055@gmail.com" />

                <TextView
                    android:id="@+id/profile_tv_edit"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/profile_tv_email"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="@dimen/_15sdp"
                    android:background="@drawable/rectangle_rounded_corner_white"
                    android:paddingBottom="@dimen/_5sdp"
                    android:paddingEnd="@dimen/_25sdp"
                    android:paddingStart="@dimen/_25sdp"
                    android:paddingTop="@dimen/_5sdp"
                    android:text="@string/edit_profile"
                    android:textColor="@color/orange_1"
                    android:textSize="@dimen/_12sdp"
                    android:visibility="gone" />

            </RelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:contentInsetStart="0dp"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay">

                <TextView
                    android:id="@+id/profile_tv_activity_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:text="@string/profile"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/_16sdp"
                    android:visibility="gone" />

            </android.support.v7.widget.Toolbar>

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

这里我在imageview中设置了Image: -

    public class ProfileActivity extends BaseActivity  {

        private AppBarLayout appBarLayout;

        private ImageView editProfileCivProfileImage;

        @Override
        protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_profile);
    editProfileCivProfileImage = findViewById(R.id.edit_profile_civ_profile_image);     

            editProfileCivProfileImage.setImageResource(R.mipmap.ic_launcher);

        }
    }

这里BaseActivity: -

    public class BaseActivity extends AppCompatActivity {

    protected CompositeDisposable compositeDisposable;

    private ProgressDialog progressDialog;
    private SahelPreferences sahelPreferences;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Log.i("compositeDisposable", ">>" + "new");
        sahelPreferences = new SahelPreferences(this, AppConstant.PREFERENCE_DEFAULT);

        compositeDisposable = new CompositeDisposable();
        progressDialog = new ProgressDialog(this);

        progressDialog.setMessage("Please Wait...");
        progressDialog.setCancelable(false);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onStop() {
        Log.i("compositeDisposable", ">>" + "clear");
        compositeDisposable.clear();
        hideLoading();
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        Log.i("compositeDisposable", ">>" + "dispose");
        compositeDisposable.dispose();
        super.onDestroy();
    }

    public void showLoading() {
        hideLoading();
        progressDialog = CommonUtil.showLoadingDialog(this);
    }

    public void hideLoading() {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
            progressDialog.cancel();
        }
    }

    public SahelPreferences getPreferences() {
        return sahelPreferences;
    }
}

任何人都可以解决这个问题。我是Android新手。在此先感谢。

1 个答案:

答案 0 :(得分:0)

试试这个

editProfileCivProfileImage.setImageDrawable(getResource().getDrawable(R.mipmap.ic_launcher));