我怎么有一个动作条图标/徽标以及重叠的内容?徽标、图标、有一个、动作

2023-09-12 21:50:04 作者:剧情再美、终究是戏

目前,我正在做我的第一个应用程序之一。我使用ActionBarSherlock。 我想提出我的标志重叠的动作条(滚动型)。

I'm currently making one of my very first applications. I'm using ActionBarSherlock. I would like to make my logo overlap the actionbar (scrollview).

目前我有main_activity.xml。在MainActivity.java我使用的setContentView查看main_activity.xml。从那以后,我用getSupportActionBar()的ActionBarSherlock。我已经使用RelativeLayout的(http://www.mkyong.com/android/android-relativelayout-example/)尝试的东西出来。这并没有真正的工作,因为有多种布局。

Currently I have main_activity.xml. In MainActivity.java I use setContentView to view main_activity.xml. After that I use getSupportActionBar() for ActionBarSherlock. I've tried things out using RelativeLayout  (http://www.mkyong.com/android/android-relativelayout-example/). That didn't really work because there are multiple layouts.

所以,我已经尝试了一些东西左右,但它最终总是盈或动作条后面,或者在到达内容之前停止。这是因为两种不同的布局,这就是我知道的。但是,我该怎么去解决这个问题?可能吗?在此先感谢!

So I've tried some things right and left, but it always ends up infront or behind the actionbar, or stops just before reaching the content. It's because of two different layouts, that's what I know. But how can I going to solve this? Is it possible? Thanks in advance!

我想: https://m.xsw88.com/allimgs/daicuo/20230912/102.png

推荐答案

您可以:

一个。分割你的形象在两个 有顶部的动作条标志,然后显示底部您的内容。

A. Split your image in two Have the top part as the ActionBar logo, then show the bottom part over your content.

乙。使用一个单一的图片 你需要的是包含只是您的标志(你可能想要的东西就像一个布局文件的ImageView 的LinearLayout 这样你就可以轻松地设置正确的页边距)。 然后调用后的setContentView 为您的活动,以增加您的标志观点:

B. Use a single image You'll need a layout file that contains just your logo (you'll probably want something like an ImageView inside a LinearLayout so you can easily set the correct margins). Then after calling setContentView for your activity, add your logo view with:

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

使用布局文件

例布局文件(logo_view.xml):

Example layout file (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>

充气布局文件:

Inflate the layout file:

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