【问题标题】:Android with Scrollview for half screen only带有 Scrollview 的 Android 仅适用于半屏
【发布时间】:2013-12-24 01:46:27
【问题描述】:

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

我想设置 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>

【问题讨论】:

    标签: android layout scrollview


    【解决方案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 部分可以滚动。

    【讨论】:

      【解决方案2】:
       <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:只将内容部分包装在滚动视图中,但由于滚动视图只能有一个子视图,因此在滚动视图内嵌套另一个线性布局。

      编辑:删除原来的&lt;/ScrollView&gt; 和多余的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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-14
        • 2012-04-06
        • 1970-01-01
        • 2013-12-16
        • 2017-04-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多