在Android SlideUp面板中以编程方式设置高度

德芙拉斯

我正在尝试做的事情::

快照


我所拥有的::我正在指这个项目


我在做什么::操作栏上的按钮onclick我正在执行滑动动作


发生了什么::当滑块出现时,我只希望显示到屏幕的一半而不是整个布局


我想要什么::

  • 所以我想以编程方式设置高度
  • 然后在外部单击时必须关闭滑动布局

我的代码::

DemoActivity.java

public class DemoActivity extends Activity {
    private static final String TAG = "DemoActivity";

    private SlidingUpPanelLayout mLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
        setContentView(R.layout.activity_demo);

        mLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
        mLayout.setPanelSlideListener(new PanelSlideListener() {
            @Override
            public void onPanelSlide(View panel, float slideOffset) {
                Log.i(TAG, "onPanelSlide, offset " + slideOffset);
            }

            @Override
            public void onPanelExpanded(View panel) {
                Log.i(TAG, "onPanelExpanded");

            }

            @Override
            public void onPanelCollapsed(View panel) {
                Log.i(TAG, "onPanelCollapsed");

            }

            @Override
            public void onPanelAnchored(View panel) {
                Log.i(TAG, "onPanelAnchored");
            }

            @Override
            public void onPanelHidden(View panel) {
                Log.i(TAG, "onPanelHidden");
            }
        });

    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.demo, menu);
        getMenuInflater().inflate(R.menu.custom_menu, menu);



        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){

        case R.id.action_cart:
            mLayout.expandPanel();
            //mLayout.hidePanel();

            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        if (mLayout != null && mLayout.isPanelExpanded()) {
            mLayout.collapsePanel();
        } else {
            super.onBackPressed();
        }
    }
}

activity_demo.xml

<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"
    tools:context=".DemoActivity" >

    <com.sothree.slidinguppanel.SlidingUpPanelLayout
        xmlns:sothree="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        sothree:dragView="@+id/dragView"
        sothree:panelHeight="68dp"
        sothree:paralaxOffset="100dp"
        sothree:shadowHeight="4dp" >

        <!-- MAIN CONTENT -->

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="?android:attr/actionBarSize" >

            <TextView
                android:id="@+id/main"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clickable="true"
                android:focusable="false"
                android:focusableInTouchMode="true"
                android:gravity="center"
                android:text="Main Content"
                android:textSize="16sp" />
        </LinearLayout>

        <!-- SLIDING LAYOUT -->

        <LinearLayout
            android:id="@+id/dragView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#eeeeee"
            android:clickable="true"
            android:focusable="false"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="68dp"
                android:background="#000000"
                android:orientation="horizontal" >
            </LinearLayout>
        </LinearLayout>
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>

</RelativeLayout>
Pragnesh Ghodaシ

你可以试试这个...

int height = getWindowManager().getDefaultDisplay().getHeight(); // getting full height of screen
mLayout.setPanelHeight(height/2); // setting half size

或这个..

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int height = dm.heightPixels;

mLayout.setPanelHeight(height/2);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何以编程方式在Android Q中打开“设置”面板?

以编程方式为 xamarin android 中的 mapfragment 设置高度

设置列表视图的动态高度,该高度以编程方式添加到android中

在Android中以编程方式更改AppBarLayout的高度

以编程方式设置Android的工具栏高度

在Android中以编程方式设置布局的大小

如何在Android中以编程方式更改布局高度

如何在android中以编程方式设置android:id?

以编程方式打开Android设置

Android铃声以编程方式设置?

如何在Android中以编程方式在EditText中设置ID

在xml中或以编程方式在android中设置位图更好?

android RelativeLayout以编程方式更改高度

Android EditText以编程方式动态调整高度

在ImageFilterView中以编程方式设置android:altSrc吗?

Android:以编程方式在ImageButton中设置图像的填充

如何在Android中以编程方式设置活动的父活动?

你可以在Android中以编程方式设置ContenetProvider吗?

以编程方式在Android中获取“屏幕锁定”设置

在Android中以编程方式设置浓度像素无法正常运行

如何在Android中以编程方式设置背景可绘制

Android 以编程方式在图层列表中设置颜色

如何在Android TextView中以编程方式设置maxLength?

在Android中以编程方式设置Google Map Api键

未在Android中以编程方式设置按钮的边距

在Android中以编程方式在textview下方设置textview

在RecycerView Android中以编程方式为项目设置重力

Android Xamarin,如何以编程方式在EditText中设置nextfocusdown?

如何在Android中以编程方式设置按钮边框颜色?