【问题标题】:Scroll view working in emulator but not working in android device滚动视图在模拟器中工作但在 android 设备中不工作
【发布时间】:2012-04-06 08:55:44
【问题描述】:

我的应用中有一个滚动视图,它在我的模拟器中运行良好,但在 android 设备中运行不正常.....我使用 minsdkversion:8 开发的应用...我在 android 2.2 中部署了我的应用强>

我的布局在下面

<?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
 android:scrollbars="vertical" 
 android:layout_height="fill_parent" 
 android:layout_width="fill_parent"
 android:background="#D2691E"> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#D2691E"
>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Branch"
android:textColor="#000000"
android:textSize="30px"
/>
<Spinner android:id="@+id/group"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:prompt="@string/group_prompt"

/>   
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Year"
android:textColor="#000000"
android:textSize="30px" />
<Spinner android:id="@+id/year"
    android:layout_width="match_parent"


 android:layout_height="wrap_content"
    android:drawSelectorOnTop="true"
    android:prompt="@string/year_prompt"

/>     

<Button android:id="@+id/ok1_button" 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" android:text="Ok1" android:ems="5">          
</Button>
 </LinearLayout>
 </ScrollView>

请给个解决办法..谢谢

【问题讨论】:

  • 设备有什么问题?滚动视图内的视图被冻结?
  • @Rahul garg ya.....我无法在设备中滚动,但我可以在模拟器中滚动
  • 在模拟器上如何通过鼠标滚动按钮或拖动光标进行滚动
  • @kumar : 检查我的答案在测试后是否已更新。
  • 好的,你测试了我的答案码吗

标签: android android-layout android-emulator scrollview


【解决方案1】:

试试这个代码

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


     <ScrollView  
     android:scrollbars="vertical" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent"
     android:background="#D2691E"> 
    <LinearLayout 
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#D2691E"
    >
    <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Branch"
    android:textColor="#000000"
    android:textSize="30px"
    />
    <Spinner android:id="@+id/group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/group_prompt"

    />   
    <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Year"
    android:textColor="#000000"
    android:textSize="30px" />
    <Spinner android:id="@+id/year"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:prompt="@string/year_prompt"

    />     

    <Button android:id="@+id/ok1_button" 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" android:text="Ok1" android:ems="5">          
    </Button>
     </LinearLayout>
     </ScrollView>
    </LinearLayout>

【讨论】:

  • 嘿,现在我也为每个布局提供了 xmlns:android="schemas.android.com/apk/res/android" 属性,但它正在工作....scrollview 可能是什么原因在我上面的代码中不起作用
  • 好的,这可能是因为您的设备中不允许滚动视图作为父布局,这可能是您使用哪个设备的原因
【解决方案2】:

在您的 2 个 Snippers 中,将您的代码替换为

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#D2691E"
    android:scrollbars="vertical" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#D2691E"
        android:orientation="vertical" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Branch"
            android:textColor="#000000"
            android:textSize="30px" />

        <Spinner
            android:id="@+id/group"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="true"
            android:prompt="@string/stringone" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Year"
            android:textColor="#000000"
            android:textSize="30px" />

        <Spinner
            android:id="@+id/year"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="true"
            android:prompt="@string/stringtwo" />

        <Button
            android:id="@+id/ok1_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="5"
            android:text="Ok1" >
        </Button>
    </LinearLayout>
</ScrollView>

复制并粘贴到您的文件中。将在 2.1 和 2.2 中工作。

【讨论】:

  • @kumar :保留整个文件,只需复制并粘贴到您的文件中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-10
  • 2012-08-19
  • 2023-03-23
  • 2011-03-04
  • 1970-01-01
相关资源
最近更新 更多