0

是否有可能将 1px 宽度(或更多像素)的图像设置为ImageViewImageView 的所有宽度并重复它,而不是为不同的方向创建单独的图像,例如

drawable-land-> 一些图像(例如 100 像素宽度)

drawable-port-> 相同但更大的图像(例如 250 像素宽度)

4

2 回答 2

0

是的,您可以使用 android 中的 Drawable 位图来做到这一点。试试这个代码

在drawable文件夹中创建一个xml文件并粘贴

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_launcher1"
android:tileMode="repeat" >
</bitmap>

将您的图像设置为上面的 src 标记..从那时起,该文件也可以用作您想要的图像..

于 2013-08-05T15:35:55.523 回答
0

要检测方向,您可以使用

Display getOrientation = getWindowManager().getDefaultDisplay();
int orient = Configuration.ORIENTATION_UNDEFINED;
if(getOrientation.getWidth()==getOrientation.getHeight()){ 
// is square
    orient = Configuration.ORIENTATION_SQUARE;
} else{ 
    if(getOrientation.getWidth() < getOrientation.getHeight()){
        // is portrait
        orient = Configuration.ORIENTATION_PORTRAIT;
    }else { 
        // is landscape
         orient = Configuration.ORIENTATION_LANDSCAPE;
    }
}

在 if 语句中,您可以相应地设置图像视图

于 2013-08-05T15:38:19.687 回答