- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在 android 中创建自己的自定义 View 组。我有两个 child 。一个是 linearLayout(它是第一个 child ,覆盖了屏幕的一半),上面有一些背景图像和按钮,另一个是 View 的扩展(它是第二个 child ,覆盖了整个屏幕),我用手指画了一些东西。
我希望(第一个 child )线性布局隐藏在(第二个 child ) View 扩展下,这样我就可以使用一些手势将第二个 child 滑动到右侧(有点像谷歌的幻灯片,youtube ) 并查看第一个子项 (LinearLayout)。问题出在 onLayout 中,我按特定顺序放置 child ,但无论我做什么,第一个 child (LinearLayout) 总是排在前面。
secondchild.layout(0,0,top,bottom);
firstchild.layout(0,0,top/2,bottom);
我也试过
firstchild.layout(0,0,top/2,bottom);
secondchild.layout(0,0,top,bottom);
但是第一个 child 总是排在最前面。
Costume ViewGroup 代码:
public class RootViewLayout extends ViewGroup {
private View mDrawView;
private View mSlideView;
private int mTop;
private int mDragRange;
public RootViewLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
mDrawView = findViewById(R.id.content_frame_white);
mSlideView = findViewById(R.id.slide_frame);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom){
bringChildToFront(mDrawView);
mDrawView.layout(0, 0, right, bottom);
mSlideView.layout(0, 0, right/2, bottom);
}
}
XML 代码:
<com.example.drawapp.RootViewLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Root_View_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<com.example.drawapp.DrawView
android:id="@+id/content_frame_white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/whitepaperwithcoffeestain">
</com.example.drawapp.DrawView>
<LinearLayout
android:id="@+id/slide_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/slidebackgrd"
android:orientation="vertical">
<Button
android:id="@+id/pen"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:background="@drawable/pic"/>
</LinearLayout>
</com.example.drawapp.RootViewLayout>
当我不放
bringChildToFront(mDrawView);
空白处放置有适当的黑色背景,但这不是我真正想要的。我希望整个屏幕都被 DrawView 覆盖(其背景为白色,上面有咖啡渍)。
有没有具体的方法告诉 children 一个叠一个?
最佳答案
您需要更改 subview 的 z 顺序。您可能应该使用 bringChildToFront()
,即
parentLayout.bringChildToFront(secondChild);
但是,效果取决于父布局的类型(例如,如果它是 LinearLayout
,那么 View 将被交换)。既然你在叠加,我猜这意味着它是一个 RelativeLayout
,然后它应该可以按你想要的方式工作。
我看到在您的情况下您使用的是自定义 ViewGroup
。如果它只是为了实现“全宽/半宽”子级,那么我建议将其换成 RelativeLayout
。添加带有 match_parent
和 firstchild
的 secondchild
作为居中 0dp View 的右侧,如 Adjust width to half screen
或者另一种可能更简单的选择是仅更改位于顶部的子项的可见性(VISIBLE 或 GONE)。
关于android - 如何设法在自定义 View 组中将一个 child 带到另一个 child 面前?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24168362/
我的收藏具有以下结构 { _id:1, parent_id:0 } { _id:2, parent_id:1 } { _id:3, parent_id:1 } { _id:4, par
到目前为止,我已经尝试过获取该对象的所有子对象,但它只带来了两个子对象。不都是 child 的 child 。我如何获取所有内容并循环获取特定名称对象 Transform[] objChild = g
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我有一个如下表 好吧,在这个表中每个用户都有一个父用户,那么如果我们选择一个用户,那么它的 id 、子代 id 和子代子代 id 应该作为数组返回。我需要一个查询来获取 Rails 中的这些值,而不使
我需要以下代码的帮助: HTML: process process 在点击 td[class=process] 时,我需要 input[name=dat
好的,所以我从中获得了一个 PHP,该 PHP 由依赖于手头动态情况的切换循环传播(我认为)。现在,当我添加一个复选框时,我希望能够使 div 中的第一个复选框具有顶部边框和侧面,没有底部。下面的只有
我正在使用 Swift 和 Sprite Kit。我有一个名为 MrNode 的 SKNode,它有多个 SKSpriteNodes 和 SKNode 子节点。一些SKNode有子节点,而这些子节点也
对不起,这个标题太俗了,但我真的不确定如何解释这个,我是新一代的 SQL 技能由于事件记录模式而退化的人之一! 基本上我在 PostgreSQL 中有三个表 客户端(一个客户端有很多 map ) -
我有这样的简单表格: 编号 parent_id 创建于 具有父/子关系...如果一行是子行,则它有一个 parent_id,否则它的 parent_id 为 0。 现在我想选择所有没有子项(因此本身)
所以我有这样的结构: 我的问题是:如何从每个主题中删除 ID 为 3Q41X2tKUMUmiDjXL1BJon70l8n2 的每个字段。我正在考虑这样的事情: admin.database().ref
这个问题在这里已经有了答案: Change opacity on all elements except hovered one (1 个回答) 关闭 5 个月前。 因此,当鼠标悬停在 child
我需要在 Delphi 5 中创建一个 QuickReport,其布局如下: +================ | Report Header +================ +========
假设我有这样的 html: Some more detailed code.... 我想知道如何在CSS中使用“A
我有一个使用 flexbox 的类似表格的布局: +--------------+---------------+-----------------+---------------+ | 1
我有一个关联,其中 user has_many user_items 和 user_items has_many user_item_images。与一个已经退出的用户。我可以创建一个新的 user_
我想选择无序列表中的前两个列表项。我可以这样选择第一项: ul li:nth-child(1) a { background: none repeat scroll 0 0 beige; }
ul li:first-child a { border-radius: 5px 5px 0 0; } ul li:last-child a { border-radius: 0 0 5p
我有一个这样的表:
或者这些术语用于指代同一事物? 我正在尝试在我的 Win32 应用程序中实现一些显示位图图像的自定义按钮。一个教程指出我应该使用 CreateWindow() 创建子窗口。 但是,我已经从另一个关于创
我想在 jquery 中获取我的 svg 的 id,我尝试了这个 jquery,但它是未定义的。 $(event.target).children('svg').attr("id") Target.e
我是一名优秀的程序员,十分优秀!