应用程序标识放置一半在动作条和半mainActivty屏幕上 [英] App logo positioned half in the ActionBar and half on the mainActivty screen
问题描述
能否像这样的机器人可以实现吗?我的猜测是不是因为你可以指定2个不同的布局一个是动作条,一个用于活动,但我可能也被误认为
Can something like this be achieved in Android? my guess is not since you can specify 2 different layouts one for the ActionBar and one for the Activity, but I may also be mistaken
推荐答案
这是一个更坚实的解决方案比 PopupWindow
previously建议。
This is a much more solid solution than the PopupWindow
previously suggested.
为标志覆盖的布局是一个简单的的ImageView
,上,我们已经设置了点击
属性真
来prevent触摸事件,从通过传播到查看
取值下方。
The layout for the logo overlay is a simple ImageView
, on which we've set the clickable
attribute to true
to prevent touch events from propagating through to View
s underneath.
logo.xml
布局:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher"
android:clickable="true" />
该方法是指与旧动作条
工作,并且依赖于家庭查看
作为锚覆盖。它,然而,很容易地修改与工具栏
支持类和它的标志查看
来工作,虽然这可能是不必要的,因为工具栏
类是查看
,可以轻松地设置和操作布局XML。
This method is meant to work with the old ActionBar
, and relies on the home View
as the anchor for the overlay. It is, however, easily modified to work with the support Toolbar
class and its logo View
, though that is probably unnecessary, since the Toolbar
class is a View
that can be easily setup and manipulated in layout XML.
private void showLogoOverlay() {
final View anchor = findViewById(android.R.id.home);
if(anchor == null) {
return;
}
final View overlay = getLayoutInflater().inflate(R.layout.logo, null, false);
final ViewGroup decor = (ViewGroup) getWindow().getDecorView();
anchor.addOnLayoutChangeListener(new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right,
int bottom, int oldLeft, int oldTop,
int oldRight, int oldBottom) {
int[] offset = new int[2];
anchor.getLocationOnScreen(offset);
decor.addView(overlay, 200, 200);
overlay.setX(offset[0]);
overlay.setY(offset[1]);
anchor.removeOnLayoutChangeListener(this);
}
}
);
}
这篇关于应用程序标识放置一半在动作条和半mainActivty屏幕上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!