第二个面板中的ScrollView无法正常工作

时间:2014-05-27 03:12:56

标签: android slidingdrawer sliding

我有Activity使用AndroidSlidingUpPanel。现在,一切都很完美。不过,我想在我的第二个面板上添加ScrollView,以添加Maps或Google音乐等相同的功能:

例如,

enter image description here

当用户有方向列表时,他/她可以拉出抽屉并滚动完整的说明。

现在,我的尝试:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<com.sothree.slidinguppanel.SlidingUpPanelLayout
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom" >

    <ScrollView
        android:id="@+id/card_scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <it.gmariotti.cardslib.library.view.CardView
                android:id="@+id/food_card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="1dp"
                android:layout_marginTop="12dp"
                android:animateLayoutChanges="true" />

            <View
                android:layout_width="match_parent"
                android:layout_height="15dp" />
        </LinearLayout>
    </ScrollView>

    <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_slide"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:paddingLeft="10dp"
                android:text="@string/slide_up"
                android:textSize="14sp" />
        </LinearLayout>

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <it.gmariotti.cardslib.library.view.CardView
                android:id="@+id/food_nutrition_card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:animateLayoutChanges="true" />

            <View
                android:layout_width="match_parent"
                android:layout_height="15dp" />
        </LinearLayout>
        </ScrollView>


    </LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

这样,显示我的内容,但不添加第二个面板的滚动视图。  我该怎么办?

注意:根据AndroidSlidingUpPanel的文档,其视图中只能有两个孩子。我使用LinearLayout作为第二个孩子,因为它是我找到显示抽屉的唯一方法。例如,TextView将取代地图中估计时间(抽屉)的内容。

由于

3 个答案:

答案 0 :(得分:0)

第二个scrollview的高度应为android:layout_height="match_parent"。祝你好运!

答案 1 :(得分:0)

    take one RelativeLayout in com.sothree.slidinguppanel.SlidingUpPanelLayout and set property layout_above="yoursecondLinearlayout" to First ScrollView and second child LinearLayout to set property alignParentBottom=true. thats it....
See below code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<com.sothree.slidinguppanel.SlidingUpPanelLayout
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom" >
     **<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >**
    <ScrollView
        android:id="@+id/card_scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        **android:layout_above="@+id/linearlayout1"**>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <it.gmariotti.cardslib.library.view.CardView
                android:id="@+id/food_card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="1dp"
                android:layout_marginTop="12dp"
                android:animateLayoutChanges="true" />

            <View
                android:layout_width="match_parent"
                android:layout_height="15dp" />
        </LinearLayout>
    </ScrollView>

    <LinearLayout
        **android:id="@+id/linearlayout1"**
        **android:layout_alignParentBottom="true"**
        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_slide"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:paddingLeft="10dp"
                android:text="@string/slide_up"
                android:textSize="14sp" />
        </LinearLayout>

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <it.gmariotti.cardslib.library.view.CardView
                android:id="@+id/food_nutrition_card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:animateLayoutChanges="true" />

            <View
                android:layout_width="match_parent"
                android:layout_height="15dp" />
        </LinearLayout>
        </ScrollView>


    </LinearLayout>
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

答案 2 :(得分:0)

通过向标题的id添加Parent并将其添加到我的代码来修复此问题:

layout.setDragView((LinearLayout) findViewById(R.id.scrolled_view));

.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<com.sothree.slidinguppanel.SlidingUpPanelLayout
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom" >

    <ScrollView
        android:id="@+id/card_scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <it.gmariotti.cardslib.library.view.CardView
                android:id="@+id/food_card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="1dp"
                android:layout_marginTop="12dp"
                android:animateLayoutChanges="true" />

            <View
                android:layout_width="match_parent"
                android:layout_height="15dp" />
        </LinearLayout>
    </ScrollView>

    <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:id="@+id/scrolled_view"
            android:layout_width="match_parent"
            android:layout_height="68dp"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/name_slide"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:paddingLeft="10dp"
                android:text="@string/slide_up"
                android:textSize="14sp" />
        </LinearLayout>

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <it.gmariotti.cardslib.library.view.CardView
                android:id="@+id/food_nutrition_card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:animateLayoutChanges="true" />

            <View
                android:layout_width="match_parent"
                android:layout_height="15dp" />
        </LinearLayout>
        </ScrollView>


    </LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>