我正在开发一个应用程序,它会在活动中启动框架后向用户显示图像及其下方的一些文本。
我正在以编程方式将drawable
资源分配给ImageView
。
ImageView image = (ImageView) rootView.findViewById(R.id.avaImage);
image.setImageDrawable(getResources().getDrawable(R.drawable.ava_green));
到目前为止一切顺利。但是当我旋转设备的屏幕时,Android会更改图像的分辨率。我希望它保持原样。我怎样才能做到这一点? 这是我的片段布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
tools:context=".NavigationActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/txtLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:text="@string/title"
android:textSize="26sp" />
<ImageView
android:id="@+id/avaImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/txtLabel"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp" />
</RelativeLayout>
</ScrollView>
答案 0 :(得分:0)
你是否在片段上设置了setRetainInstance(true)并在Maninfest.xml中添加了android:configChanges =“keyboardHidden | orientation | screenSize”以阻止活动重置旋转?