问题描述
比方说,我想堆叠卡,我要穿上国王之上的女王,但仍然有国王的前20名左右的像素是可见的,所以你可以告诉它是女皇下。你怎么做到这一点?
我定义网格布局,线性布局容器。每个容器包含一个的ImageButton。最近我可以得到它侵占的ImageButton缩小占领下的ImageButton
就像这样:
我想堆叠imagebuttons,但仍然有潜在的imagebuttons仍然可以点击。
编辑:
我能够通过广泛的搜索,并在这里学习了很多关于意见看着办吧。
现在,我使用
LinearLayout.LayoutParams LP =新LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0,0,0,-60);
view.setLayoutParams(LP);
您可以设置的android:layout_marginBottom = - 50dp
的顶视图,以重叠查看下方。在这里, 50dp 的是要重叠的意见数量。
这样的:
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent> <的LinearLayout
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerHorizontal =真
机器人:layout_centerVertical =真
机器人:方向=垂直> <的ImageButton
机器人:ID =@ + ID / imageButton1
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:背景=#FF0000
机器人:layout_marginBottom = - 50dp/> <的ImageButton
机器人:ID =@ + ID / imageButton2
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:背景=#00FF00
机器人:layout_marginBottom = - 50dp/> <的ImageButton
机器人:ID =@ + ID / imageButton3
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:背景=#0000FF/> < / LinearLayout中>< / RelativeLayout的>
通过code:
的ImageButton imageButton1 =(的ImageButton)findViewById(R.id.imageButton1);
LinearLayout.LayoutParams的LayoutParams =(的LayoutParams)imageButton1
.getLayoutParams();
layoutParams.setMargins(layoutParams.leftMargin,
layoutParams.topMargin,layoutParams.rightMargin,
(layoutParams.bottomMargin - 50));
imageButton1.setLayoutParams(的LayoutParams);
Let's say I'm trying to stack cards, and I want to put a queen on top of a king, but still have the top 20 or so pixels of the king be visible so you can tell it's under the queen. How do you do this?
I've defined a grid layout, with linear layout containers. Each container contains one imagebutton. The closest I can get it is the encroaching imagebutton shrinks under the occupying imagebutton.
Like so:http://i.stack.imgur.com/broaD.png
I would like to stack the imagebuttons, but still have the underlying imagebuttons still be clickable.
Edit:I was able to figure it out by extensive searching here and learning a lot about views.I'm now using
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0, 0, 0, -60);
view.setLayoutParams(lp);
You can set android:layout_marginBottom="-50dp"
for the top view so as to overlap the view below it. Here, 50dp is the amount by which you want to overlap the views.
Like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#ff0000"
android:layout_marginBottom="-50dp" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#00ff00"
android:layout_marginBottom="-50dp" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#0000ff" />
</LinearLayout>
</RelativeLayout>
Through code:
ImageButton imageButton1 = (ImageButton) findViewById(R.id.imageButton1);
LinearLayout.LayoutParams layoutParams = (LayoutParams) imageButton1
.getLayoutParams();
layoutParams.setMargins(layoutParams.leftMargin,
layoutParams.topMargin, layoutParams.rightMargin,
(layoutParams.bottomMargin - 50));
imageButton1.setLayoutParams(layoutParams);
这篇关于如何使浏览指定的量互相重叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!