Android版Scrollview仅限半屏

时间:2013-12-24 01:46:27

标签: android layout scrollview

Rite现在,整个屏幕都可以滚动。

enter image description here

我想设置B部分(参考照片)只能滚动,同时A部分(视频部分) 是固定的。以下是我的代码仪式。请帮忙。

<LinearLayout --some code here-->
    <ScrollView
        --some code here-->
        <LinearLayout
                android:id="@+id/videoPlayer"
                >
            <VideoView
                   --some code here--/>
            <MediaController
                    android:layout_width="fill_parent"
                    />
            <TextView
                    --some code />
            <TextView
                    --some code />
            <ImageView some code
                </ImageView>
            <RelativeLayout --some code here-->

                <TextView
                        android:id="@+id/scarfPrice"
                        />
                <Button android:id="@+id/btnPurchase"
                        />
            </RelativeLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

2 个答案:

答案 0 :(得分:1)

 <LinearLayout --some code 
        --some code here-->
        <LinearLayout
                android:id="@+id/videoPlayer"
                >
            <VideoView
                   --some code here--/>
            <MediaController
                    android:layout_width="fill_parent"
                    />
            <ScrollView>
                <LinearLayout>
                    <TextView
                            --some code />
                    <TextView
                            --some code />
                    <ImageView some code
                        </ImageView>
                    <RelativeLayout --some code here-->

                        <TextView
                                android:id="@+id/scarfPrice"
                                />
                        <Button android:id="@+id/btnPurchase"
                                />
                    </RelativeLayout>
                </LinearLayout>
            </ScrollView>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

tldr:仅将内容部分包装在scrollview中,但由于scrollview只能有一个子节点,因此在scrollview内部嵌套另一个linearlayout。

编辑:删除原始</ScrollView>和冗余LinearLayout

 <LinearLayout --some code 
        --some code here-->
            >
        <VideoView
               android:id="@+id/videoPlayer"
               --some code here--/>
        <MediaController
                android:layout_width="fill_parent"
                />
        <ScrollView>
            <LinearLayout>
                <TextView
                        --some code />
                <TextView
                        --some code />
                <ImageView some code
                    </ImageView>
                <RelativeLayout --some code here-->

                    <TextView
                            android:id="@+id/scarfPrice"
                            />
                    <Button android:id="@+id/btnPurchase"
                            />
                </RelativeLayout>
            </LinearLayout>
        </ScrollView>
    </LinearLayout>

答案 1 :(得分:1)

<LinearLayout>
   <LinearLayout android:layout_weight="2">
        <!-- Part A -->
   </LinearLayout>
   <ScrollView android:layout_weight="3">
       <LinearLayout>
           <!-- Part B -->
       </LinearLayout>
   </ScrollView>
</LinearLayout>

A部分将占据屏幕的2/5。 B部分将占据屏幕的3/5,只有部分B可以滚动。