【发布时间】:2015-10-31 18:05:32
【问题描述】:
我正在使用myLinearLayout.setBackgroundResource(R.drawable.my_drawable) 设置LinearLayout 的背景。使用此方法而不是让图像拉伸以适应LinearLayout 时,有什么方法可以保持源图像的纵横比(必要时缩放以适应)?
xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/background_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
...
</LinearLayout>
java 文件:
backgroundLayout.setBackgroundResource(R.drawable.my_drawable);
【问题讨论】: