java - 我如何让 ActionBar 图标/ Logo 也与内容重叠?

标签 java android android-actionbar actionbarsherlock

我目前正在制作我的第一个应用程序。我正在使用 ActionBarSherlock。 我想让我的 Logo 与操作栏( ScrollView )重叠。

目前我有 main_activity.xml。在 MainActivity.java 中,我使用 setContentView 来查看 main_activity.xml。之后,我将 getSupportActionBar() 用于 ActionBarSherlock。我已经尝试使用 RelativeLayout (http://www.mkyong.com/android/android-relativelayout-example/)。这并没有真正起作用,因为有多种布局。

所以我左右尝试了一些东西,但它总是在操作栏的前面或后面结束,或者在到达内容之前停止。这是因为两种不同的布局,这就是我所知道的。但是我该如何解决呢?可能吗?提前致谢!

我想要的: http://f.cl.ly/items/3N0w243N1t2Q3i1H1f1k/Untitled-1.png

最佳答案

您可以:

A.将您的图像一分为二
将顶部作为 ActionBar Logo ,然后在您的内容上显示底部。

B.使用单张图片
您需要一个仅包含您的 Logo 的布局文件(您可能需要 LinearLayout 中的 ImageView 之类的东西,以便您可以轻松设置正确的边距)。 然后在为您的 Activity 调用 setContentView 之后,添加您的 Logo View :

ViewGroup decorViewGroup = (ViewGroup) getWindow().getDecorView();
decorViewGroup.addView(logoView);

使用布局文件

示例布局文件 (logo_view.xml):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/logo_image"
        android:scaleType="center"
        android:layout_marginLeft="10dip"
        />

</LinearLayout>

扩充布局文件:

LayoutInflater inflater = LayoutInflater.from(this);
View logoView = inflater.inflate(R.layout.logo_view, null, false);

关于java - 我如何让 ActionBar 图标/ Logo 也与内容重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14131045/

相关文章:

java - 为什么即使在 spring 服务类的第二种方法中 propagation=Propagation.REQUIRES_NEW 时事务也会回滚?

android - 从 Android 应用程序转换 m3u8 文件

android - 通过样式更改操作栏溢出菜单项的高度

android - 应用程序 ActionBar 中的后退按钮

android - ActionBar 选项卡导航与自定义 ActionBar View 奇怪的行为

java - 如何创建与 PreferenceFragment 类别标题相同的标题?

Java线程池内存泄漏

java - 使用 Runtime.exec() 从另一个目录执行程序

java - 在对话框中动态添加 View

android - 如何从 X/Y 坐标获取 View