【问题标题】:android scroll view is giving me problemsandroid滚动视图给我带来了问题
【发布时间】:2016-06-20 04:14:02
【问题描述】:

我创建了一个具有 ScrollView 的 android 测验应用程序。问题是当您向下滚动时,它会自动返回,因此用户无法选择底部的答案。我该如何解决这个问题?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/relatively"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/add"
    android:orientation="vertical"
    android:weightSum="1" >

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="292dp"
        android:id="@+id/scrollView"
        android:layout_gravity="center_horizontal"
        android:layout_weight="0.20">

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.90"
            android:orientation="vertical"
            android:weightSum="1" >

            <LinearLayout
                android:id="@+id/linearLayout11"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.20"
                android:orientation="horizontal"
                android:weightSum="1" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/score"
                        android:layout_width="160dp"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_marginRight="10dp"
                        android:gravity="center"
                        android:text="Maraga : 0"
                        android:textColor="#bc42f4"
                        android:textSize="25.0sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/timers"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_marginRight="10dp"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="00:00:49"
                        android:textColor="#ab0afb"
                        android:textSize="25.0sp"
                        android:textStyle="bold"
                        android:textIsSelectable="true" />
                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout12"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight=".8"
                android:orientation="vertical"
                android:weightSum="1" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.40" >

                    <TextView
                        android:id="@+id/txtQuestion"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_gravity="center"
                        android:layout_marginTop="5dp"
                        android:gravity="center"
                        android:text="15*2*1-1"
                        android:textColor="#fd0213"
                        android:textSize="35.0sp"
                        android:textStyle="bold" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="295dp"
                    android:layout_height="381dp"
                    android:orientation="vertical"
                    android:weightSum="1"
                    android:gravity="fill_horizontal|start|end|center_horizontal"
                    android:layout_gravity="center_horizontal">

                    <Button
                        android:id="@+id/button1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="20dp"
                        android:background="#09bcf8"
                        android:gravity="center"
                        android:text="30"
                        android:textColor="#ffffff"
                        android:textSize="25.0sp" />

                    <Button
                        android:id="@+id/button2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="20dp"
                        android:background="#2cf309"
                        android:gravity="center"
                        android:text="29"
                        android:textColor="#ffffff"
                        android:textSize="25.0sp" />

                    <Button
                        android:id="@+id/button3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="20dp"
                        android:background="#7f0af4"
                        android:gravity="center"
                        android:text="32"
                        android:textColor="#ffffff"
                        android:textSize="25.0sp" />

                </LinearLayout>


            </LinearLayout>


        </LinearLayout>
    </ScrollView>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"

        ads:adUnitId="@string/banner_ad_unit_id"
        android:layout_weight="1.5"
        android:transitionGroup="false">
    </com.google.android.gms.ads.AdView>


</LinearLayout>

【问题讨论】:

  • 我认为你写错了属性。
  • 你能说明一下到底想做什么。首先是在滚动视图中添加 fillViewport=true
  • 将滚动视图高度更改为wrap_content.!!
  • @jankigadhiya 当我在滚动视图上说 wrap_content 时广告不显示,
  • @Vishal Halani 我试过你的解决方案它没有任何区别

标签: android scrollview


【解决方案1】:

删除这一行:android:layout_weight="0.20" 在您的滚动视图中。

【讨论】:

    【解决方案2】:

    试试这个代码,我在你的代码中改变了很多东西

    你做了很多不必要的布局。确保下次创建视图时布局尽可能少。因为它会加载图形。

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollView"
        android:orientation="vertical"
        android:fillViewport="true"
        android:layout_gravity="center_horizontal">
    
        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:weightSum="1"
             >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:paddingLeft="30dp"
                android:paddingRight="30dp"
                android:layout_weight="0.80"
                android:orientation="vertical">
    
            <LinearLayout
                android:id="@+id/linearLayout11"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:weightSum="1"
                android:orientation="horizontal">
                    <TextView
                        android:id="@+id/score"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="Maraga : 0"
                        android:layout_weight="0.5"
                        android:textColor="#bc42f4"
                        android:textSize="25.0sp"
                        android:textStyle="bold" />
    
                    <TextView
                        android:id="@+id/timers"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_marginRight="10dp"
                        android:layout_weight="0.5"
                        android:gravity="center"
                        android:text="00:00:49"
                        android:textColor="#ab0afb"
                        android:textSize="25.0sp"
                        android:textStyle="bold"
                        android:textIsSelectable="true" />
                </LinearLayout>
    
    
                    <TextView
                        android:id="@+id/txtQuestion"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="5dp"
                        android:gravity="center"
                        android:text="15*2*1-1"
                        android:textColor="#fd0213"
                        android:textSize="35.0sp"
                        android:textStyle="bold" />
    
    
                    <Button
                        android:id="@+id/button1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="20dp"
                        android:background="#09bcf8"
                        android:gravity="center"
                        android:text="30"
                        android:textColor="#ffffff"
                        android:textSize="25.0sp" />
    
                    <Button
                        android:id="@+id/button2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="20dp"
                        android:background="#2cf309"
                        android:gravity="center"
                        android:text="29"
                        android:textColor="#ffffff"
                        android:textSize="25.0sp" />
    
                    <Button
                        android:id="@+id/button3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="20dp"
                        android:background="#7f0af4"
                        android:gravity="center"
                        android:text="32"
                        android:textColor="#ffffff"
                        android:textSize="25.0sp" />
    
    
            </LinearLayout>
            <com.google.android.gms.ads.AdView
                android:id="@+id/adView"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                ads:adSize="SMART_BANNER"
                ads:adUnitId="@string/banner_ad_unit_id"
                android:layout_weight="0.20"
                android:transitionGroup="false">
            </com.google.android.gms.ads.AdView>
        </LinearLayout>
    
    
    </ScrollView>
    

    【讨论】:

      猜你喜欢
      • 2011-05-22
      • 2011-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多