中央的位图和重复边缘像素 [英] Center a bitmap and repeat the edge pixel

查看:359
本文介绍了中央的位图和重复边缘像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一个形象在我的Andr​​oid应用背景。如果图像不适合屏幕,我希望图像水平居中和垂直方向突破。剩余屏幕区域应当通过重复边填充。

I am trying to use an image as background in my android app. If the image doesn't fit the screen I want the image to be centered horizontally and topped vertically. The remaining screen area should be filled by repeating the edges.

我的布局XML看起来是这样的:

My layout xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="@drawable/background_image"
>
    <ScrollView
        android:layout_width="fill_parent" android:layout_height="fill_parent"
    >
    ...
    </ScrollView>
</LinearLayout>    

我试图左和右列以及像素作为伸缩性使用draw9patch的顶行标记。这似乎更小的设备,但不工作对Galaxy Tab的10.1和摩托罗拉Xoom。边缘垂直而不是水平反复。

I tried to mark the left and right column as well as the top row of pixels as stretchable using draw9patch. That seems to work on smaller devices, but not on Galaxy Tab 10.1 and Motorola Xoom. The edge is repeated vertically but not horizontally.

我也试图创建一个XML抽拉与TILEMODE =钳

I also tried to create an xml-drawable with tileMode="clamp"

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:filter="true"
    android:gravity="center"
    android:tileMode="clamp"
    android:src="@drawable/background"
/>

但是,这并不让我水平居中的图像。
我怎样才能结合夹具和CENTER_HORIZONTAL?

but that doesn't allow me to center the image horizontally. How can I combine clamp and center_horizontal?

推荐答案

按照<一个href=\"http://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html#attr_android:tileMode\">documentation 当启用平铺模式重力被忽略。

Per the documentation "Gravity is ignored when the tile mode is enabled."

自定义绘制可以用来做这个。 这里是在左侧和右侧有水平居中的图像夹紧的一个例子。

A custom drawable can be used to do this. Here is an example of clamping on the left and right with a horizontally centered image.

这篇关于中央的位图和重复边缘像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆