像浏览器方法一样调整Dialog Fragment的大小

时间:2017-09-09 09:20:54

标签: android android-fragments

enter image description here enter image description here

您好

我的问题是我想调整我的片段大小我向上/向下滑动片段然后我成功了但是问题是片段上的内容不会调整大小所以我的问题是如何调整大小片段内的内容还是可能吗?

我的代码看起来像这样

private View.OnTouchListener onTouchListener = new View.OnTouchListener(){
    @Override
    public boolean onTouch(View v, MotionEvent event) {

        int minWidth = (int)((double)main_container.getWidth() * .33);
        int maxHeight = main_container.getHeight();
        float container_ratio = (float)main_container.getHeight() / (float)main_container.getWidth();

        int height = (int)event.getY();
        int width = (int)(event.getY() / container_ratio);

        if (width < minWidth || height > maxHeight) {
            return true;
        }

        if (prevTouchEvent == MotionEvent.ACTION_MOVE && oldY != event.getY() && oldY != -1) {

            RelativeLayout.LayoutParams layout = (RelativeLayout.LayoutParams)fragment_broadcast.getLayoutParams();
//                layout.setMargins(0, 0, (int)ScreenUtils.dipToPixel(MainActivity.this, 10), 0);

            layout.height = height;
            layout.width = width;
            fragment_broadcast.setLayoutParams(layout);

        }

    }
}

1 个答案:

答案 0 :(得分:0)

您可以在片段的布局上实施View.OnLayoutChangeListener界面,或覆盖onSizeChanged。然后根据调整大小来改变片段所需的内容。