2

ここのリンクからスライド パネルを使用しようとしていますが、画像に示されている問題に直面しています。 ここに画像の説明を入力

私の考えは、ユーザーが下のメニューを上にスワイプしたときにカスタム コンテンツを作成し、このコンテンツをスクロールできるようにすることです。しかし、パネルが固定状態になると、コンテンツの一部が表示されないため、コンテンツの高さが正しく設定されていないように見えます。

上記のリンクからサンプルをダウンロードしましたが、既に問題が発生しています。を追加して、小さな変更を加えましたscrollview

何か不足していますか?どんな助けでも大歓迎です。

<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:collapsedHeight="68dp"
    sothree:dragView="@+id/name"
    sothree:shadowHeight="4dp" >

    <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
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#eee"
        android:clickable="true"
        android:focusable="false"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="68dp"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/name"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"
                android:textSize="14sp" />

            <Button
                android:id="@+id/follow"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center_vertical|right"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:textSize="14sp" />
        </LinearLayout>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:id="@+id/slide_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/image"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/graphic" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="teste" />

                <ImageView
                    android:id="@+id/image"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/graphic" />

                <ImageView
                    android:id="@+id/image"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/graphic" />
            </LinearLayout>
        </ScrollView>
    </LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</RelativeLayout>
4

1 に答える 1

0

この問題は、スライド ビューが完全に測定され、部分的に画面外に配置されるために発生します。ビューを上にスライドしても、位置だけでサイズは変わりません。これは、固定されているときに ScrollView が完全に表示されないことを意味します。

私が思いついた解決策は、PanelSlideListener イベントを使用して、スライド ビューの位置が変化したときに ScrollView のサイズを変更することです。ScrollView に「@+id/scroll_view」という ID を指定し、AndroidSlidingUpPanel デモ アプリから以下の onCreate() コードのこの変更されたセクションを使用します。

final float anchorPoint = 0.5f;
final ScrollView scrollView = (ScrollView) findViewById(R.id.scroll_view);
final SlidingUpPanelLayout layout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
layout.setAnchorPoint(anchorPoint);
layout.setPanelSlideListener(new PanelSlideListener() {
    @Override
    public void onPanelSlide(View panel, float slideOffset) {
        Log.i(TAG, "onPanelSlide, offset " + slideOffset);
        setActionBarTranslation(layout.getCurrentParalaxOffset());
        resizeScrollView(panel, slideOffset);
    }

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

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

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

    private void resizeScrollView(View panel, float slideOffset) {
        // The scrollViewHeight calculation would need to change based on
        // what views you have in your sliding panel. The calculation below
        // works because your layout has 2 child views.
        // 1) The row with the drag view which is layout.getPanelHeight() high.
        // 2) The ScrollView.
        final int scrollViewHeight =
            (int) ((panel.getHeight() - layout.getPanelHeight()) * (1.0f - slideOffset));
        scrollView.setLayoutParams(
            new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                                          scrollViewHeight));
    }
});
于 2014-04-25T22:22:55.580 に答える