【发布时间】:2015-01-21 17:06:42
【问题描述】:
我一直在尝试制作一个 ActionBar。起初我决定将其绘制为图像(下图中的第二个 actionBar),但注意到在某些设备上 Image 不会占据整个屏幕宽度。至于原来的 ActionBar,我在我的主 Activity onCreate 方法中使用了这段代码:
final ActionBar actionBar = getActionBar();
@SuppressWarnings("deprecation")
BitmapDrawable background = new BitmapDrawable (BitmapFactory.decodeResource(getResources(), R.drawable.actionbar));
actionBar.setBackgroundDrawable(background);
//actionBar.setIcon(android.R.color.transparent);
actionBar.setDisplayShowTitleEnabled(false);
第一个 ActionBar 有一个浅色主题,图像被拉伸。我怎样才能让它变得透明,有没有办法设置 ActionBar 的高度,这样它就不会看起来那么拉伸了?我也试过用样式来做这个,结果是一样的。
编辑我遵循了 vinitius 的回答,所以我现在有了这个:result 图片是 482x104,我的手机是 480x800。这与将其用作纯图像时发生的问题相同。图片在 drawable-hdpi 文件夹中。
EDIT 2 通过将 android:scaleType="fitXY" 添加到 ImageView 中,它将使整个图像拉伸。
actionbar_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#3383A8" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:src="@drawable/actionbar" />
</RelativeLayout>
EDIT 3 如果我将图像添加为RelativeLayout 背景,则其填充不适合较大设备上的整个宽度。如果我将它用作更大宽度设备上的图像,它将被拉伸。 Image
【问题讨论】:
-
似乎在我添加“background.setTileModeX(android.graphics.Shader.TileMode.CLAMP);”时发生了变化现在我只需要一种方法来删除 ActionBar 背景中的浅色主题并更改高度,因为图像不适合..
-
那么,它对你有用吗?
-
它适用于较小的设备,但不适用于较大的设备。我应该回到使用普通的 ActionBar,因为图像被拉伸了。
-
但是您的图像尺寸是否正确(mdpi、hdpi、xhdpi....)?