7

SlidingDrawerアプリケーションで使用したい。しかし、 を非表示にして、を閉じたときにコンテンツの20%handleを表示する必要があります。また、すべてのスライド (タッチまたはドラッグ)アクションをに割り当てたいと考えています。誰かがこれに対する解決策を持っている場合は、私を助けてください。SlidingDrawerhandlecontent

私が試した次のコードスニペットを参照してください。

<View
    android:id="@id/handle"
    android:layout_width="0dip"
    android:layout_height="fill_parent" />

<LinearLayout
    android:id="@id/content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sliding_drawer" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sliding_drawer" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sliding_drawer" />
</LinearLayout>

ここに私の活動があります:

     import android.app.Activity;
     import android.graphics.Color;
     import android.os.Bundle;
     import android.view.View;
     import android.widget.SlidingDrawer;
     import android.widget.SlidingDrawer.OnDrawerCloseListener;
     import android.widget.SlidingDrawer.OnDrawerOpenListener;

     public class SlidingDrawerActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final SlidingDrawer drawer = (SlidingDrawer) findViewById(R.id.drawer);
        drawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {

            public void onDrawerClosed() {
                // TODO Auto-generated method stub
                drawer.setBackgroundColor(Color.BLACK);
            }
        });

        drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {

            public void onDrawerOpened() {
                // TODO Auto-generated method stub
                drawer.setBackgroundColor(Color.BLUE);
            }
        });

        View content = drawer.getContent();
        content.setClickable(true);
        content.setTouchDelegate(drawer.getHandle().getTouchDelegate());
    }
}

ここでは、 を設定して を非表示にすることhandleができますが、を閉じてアクションを の に設定したときにコンテンツの20%width=0dipを表示する方法を知ることができません。SlidingDrawerContentSlidingDrawer

touchDelegateハンドルの を取得してに設定してみましContentたが、うまくいきません。この問題を解決するために私を助けてください。

4

4 に答える 4

0

私はあなたのように何かをするつもりです。

Slidedrawer は廃止されたため、MultiDirectionSlidingDrawer という名前のカスタム スライドドローを使用しました。インターネットで見つけたコードは次のとおりです。 MultiDirectionSlidingDrawer ソース コード

コンテンツ ビューをハンドルとして表示するには、ハンドルではなくコンテンツを非表示にします。コンテンツ ビューの高さを 0 ディップに設定しました

<it.sephiroth.demo.slider.widget.MultiDirectionSlidingDrawer
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/drawer"
    custom:handle="@+id/handle"
    custom:content="@+id/content"
    custom:direction="topToBottom"
    custom:animateOnClick="false"
    custom:allowSingleTap="false"

    >
    <LinearLayout 
        android:id="@id/handle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center"
        >
        <!--
        paste your content here
        -->
    </LinearLayout>
    <LinearLayout 
        android:id="@id/content"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        android:gravity="center"
        >

    </LinearLayout>
</it.sephiroth.demo.slider.widget.MultiDirectionSlidingDrawer>

私の引き出しは上から始まるので、 onMeasureで上のオフセットを計算します

@Override
protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec )
{
    int widthSpecMode = MeasureSpec.getMode( widthMeasureSpec );
    int widthSpecSize = MeasureSpec.getSize( widthMeasureSpec );

    int heightSpecMode = MeasureSpec.getMode( heightMeasureSpec );
    int heightSpecSize = MeasureSpec.getSize( heightMeasureSpec );

        if ( widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED ) { throw new RuntimeException(
            "SlidingDrawer cannot have UNSPECIFIED dimensions" ); }

        final View handle = mHandle;
        measureChild( handle, widthMeasureSpec, heightMeasureSpec );

        //Custom top offset
        int intHandleHeight = handle.getHeight();
        mTopOffset = intHandleHeight*80*-1/100;

        if ( mVertical ) {
            int height = heightSpecSize - handle.getMeasuredHeight() - mTopOffset;
            mContent.measure( MeasureSpec.makeMeasureSpec( widthSpecSize, MeasureSpec.EXACTLY ), MeasureSpec.makeMeasureSpec( height, MeasureSpec.EXACTLY ) );
        } else {
            int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset;
            mContent.measure( MeasureSpec.makeMeasureSpec( width, MeasureSpec.EXACTLY ), MeasureSpec.makeMeasureSpec( heightSpecSize, MeasureSpec.EXACTLY ) );
        }

        setMeasuredDimension( widthSpecSize, heightSpecSize );
    }
于 2013-06-05T05:14:40.247 に答える
0

今のSlidingDrawerでは、その20%に切り分けられるものを扱っていない限り、これは不可能だと思います。SlidingDrawer のソースを見ると、具体的open()にはプライベート メソッドopenDrawer(). これが何をするかです:

private void openDrawer() {
    moveHandle(EXPANDED_FULL_OPEN);
    mContent.setVisibility(View.VISIBLE);

    if (mExpanded) {
        return;
    }

    mExpanded = true;

    if (mOnDrawerOpenListener != null) {
        mOnDrawerOpenListener.onDrawerOpened();
    }
}

ご覧のとおり、ハンドルが動き始めるまでコンテンツ (「引き出し」) は表示されません。引き出しが動いているときはフックが表示されず、開始時または終了時にのみフックが表示されるため、ハンドルまたは引き出しの内容を動的に更新することはできません。

画像を扱う場合、20% と 80% の 2 つの部分に分割できます。しかし、3 つの TextView を使用しているため、それはオプションではないようです。

オプションは、SlidingDrawer のソースを取得して独自のクラスを作成することだと思います。そうすれば、描画の処理方法を完全に制御できますが、それでもすべてのリスナーを再利用できます。ソースへのリンクは次のとおりです: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/SlidingDrawer.java

于 2012-09-06T02:47:27.930 に答える
0

私は非常に似たようなことをしようとしています。運が良かったですか?

SlidingDrawer を閉じたときにコンテンツの 20% を表示するには、SemiClosedSlidingDrawer を使用することをお勧めします。これが最初に見つけた場所だと思います:http://pastebin.com/FtVyrcEb

また、これを res/values/ の attr.xml ファイルに追加しました

<!-- SemiClosedSlidingDrawer -->
<declare-styleable name="SemiClosedSlidingDrawer">
    <attr name="handle" format="integer" />
    <attr name="content" format="integer" />
    <attr name="topOffset" format="dimension" />
    <attr name="bottomOffset" format="dimension" />
    <attr name="allowSingleTap" format="boolean" />
    <attr name="animateOnClick" format="boolean" />
    <attr name="semiClosedOrientation" format="string" />
    <attr name="semiClosedContentSize" format="dimension" />
</declare-styleable>
于 2013-07-18T16:03:52.690 に答える