我有一个ImageView,其中包含了一点"?“作为图像。这个图像被拉伸了,看起来很难看。因此,我尝试将ImageViews.caleType-属性设置为fitCenter,但没有任何效果。我也尝试了所有其他的scaleTypes,但是没有影响我的布局。由于用户稍后可以在ImageView中上传任何大小的图片,所以我希望我的ImageView始终适合它的中心位置。以下是我的xml文件:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:background="@android:drawable/ic_menu_save"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="name of question"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:id="@+id/imageViewQuestion"
android:layout_gravity="center_horizontal"
android:background="@android:drawable/ic_menu_help"
android:layout_weight="1"
android:cropToPadding="false"
android:onClick="clickQuestion"
android:scaleType="centerCrop" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textViewQuestion"
android:layout_gravity="center_horizontal"
android:layout_weight="0.11"
android:textAlignment="center"
android:hint="Question"
android:onClick="clickQuestion"
android:gravity="center" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.60">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="1"
android:id="@+id/button1"
android:layout_weight="2"
android:onClick="clickButtonEdit" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="2"
android:id="@+id/button2"
android:layout_weight="2"
android:onClick="clickButtonEdit" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="3"
android:id="@+id/button3"
android:layout_weight="2"
android:onClick="clickButtonEdit" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="4"
android:id="@+id/button4"
android:layout_weight="2"
android:onClick="clickButtonEdit" />
</LinearLayout>
</LinearLayout>
有人看到我的错误了吗?
发布于 2015-03-11 16:09:58
尝试使用src而不是background:
替换
android:background="@android:drawable/ic_menu_help"通过
android:src="@android:drawable/ic_menu_help"https://stackoverflow.com/questions/28991639
复制相似问题