是否可以将窗口小部件宽度指定为可用屏幕宽度的一半,并使用声明性xml进行操作?
我在android中创建自己的自定义视图组.我有两个孩子.一个是linearLayout(它是第一个孩子,占据屏幕的一半),上面有一些背景图像和按钮,另一个是View的扩展(它是第二个孩子,覆盖整个屏幕),我用手指画一些东西.
我希望(第一个孩子)线性布局隐藏在视图的(第二个孩子)扩展下,以便我可以使用一些手势将第二个孩子滑动到右侧(有点像google,youtube的幻灯片)并且看到第一个孩子(LinearLayout).问题出在onLayout上我按照一定的顺序放置孩子,但无论我做什么,第一个孩子(LinearLayout)总是在前面.
secondchild.layout(0,0,top,bottom);
firstchild.layout(0,0,top/2,bottom);
Run Code Online (Sandbox Code Playgroud)
我也试过了
firstchild.layout(0,0,top/2,bottom);
secondchild.layout(0,0,top,bottom);
Run Code Online (Sandbox Code Playgroud)
但第一个孩子总是名列前茅.
服装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, …Run Code Online (Sandbox Code Playgroud)