我有一项活动,我现在称之为主动。我想知道如何将背景放在上面。我知道如何通过添加android:background="@drawables/background"
但我想将它对齐到右下角(Gravity)并保持原始比例,因为背景标签正在拉伸它
这是我到目前为止所得到的。 styles.xml文件和线性布局上的背景标记设置为@ style / Background
样式文件:
<style name="Background">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/background"
android:gravity="bottom|right"
/>
</style>
我可以添加/更改(或我可以做的任何其他事情)使可绘制的“锁定”到右下角?
由于
答案 0 :(得分:1)
您可以创建一个新的位图可绘制,指定源可绘制和 gravity ,然后使用该drawable作为背景。
例如,创建一个名为aligned_background.xml
的新位图可绘制:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="bottom|right"
android:src="@drawable/background" />
然后将背景设置为@drawable/aligned_background
。
答案 1 :(得分:0)
大家好,如何看待这个。 在此页面上的第一个答案的帮助下。我有一个适合我的文件。 我有一个可绘制的位图XML文件。然后main.xml上的Linear布局将其背景标记设置为“@ drawable / aligned background”
正是我想要的文件(aligned_background)如下: 现在好了! 我知道了。 这是我的最终位图drawable,对我来说很棒!
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="bottom|right"
android:src="@drawable/background"
android:adjustViewBounds="true"
android:scaleType="fitStart"/>
谢谢!