0
我使用myLinearLayout.setBackgroundResource(R.drawable.my_drawable)
设置LinearLayout
的背景。有什么方法可以在使用此方法时保持源图像的纵横比(在必要时缩放以适合),而不是让图像伸展以适合LinearLayout
?使用LinearLayout.setBackgroundResource()保持纵横比()
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);
我用这个答案,但是对于根元素:http:// stackov用'FrameLayout'而不是'RelativeLayout' erflow.com/q/22875453/1438339。在实践中,可能没有什么区别,或者我应该想象得很好。 –