Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-can';t获取滚动视图以正确滚动列表_Android_Android Layout - Fatal编程技术网

Android-can';t获取滚动视图以正确滚动列表

Android-can';t获取滚动视图以正确滚动列表,android,android-layout,Android,Android Layout,我有一个非常基本的观点: <?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="fil

我有一个非常基本的观点:

<?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"
        >         

<TextView
    android:id="@+id/question_label"    
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Your question: "
    />     

<TextView
    android:id="@+id/question"    
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text=""
    />         

        <EditText  
            android:id="@+id/question_text"  
            android:layout_height="wrap_content"  
            android:hint="@string/question_comment_hint"  
            android:inputType="textMultiLine"  
            android:lines="4"  
            android:layout_width="fill_parent">  
        </EditText>

<Button  
            android:id="@+id/submit"  
            android:layout_height="wrap_content"  
            android:text="@string/submit"  
            android:onClick="sendFeedback"  
            android:layout_width="fill_parent">  
        </Button>       



<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >    

<TextView
    android:id="@+id/please_wait"    
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Please wait while the discussion loads..."
    />     

    <ListView
    android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label"
        android:textSize="20px" >        
    </ListView>         

    </LinearLayout>
</ScrollView>

</LinearLayout>

我希望它能让用户滚动浏览整个评论列表。现在,当屏幕上的评论多于空间时,屏幕不会向下滚动

你知道我应该改变什么来实现评论的滚动吗


谢谢

似乎您正试图在ListView中的注释上方添加标题。正如coder所指出的,您不应该将ListView放在ScrollView中。您应该考虑将标题视图直接添加到ListView(请参阅)。

似乎您正试图在ListView中的注释上方添加标题。正如coder所指出的,您不应该将ListView放在ScrollView中。您应该考虑将标题视图直接添加到ListView中(请参阅)。

我将完全取消scrollview,这取决于我认为您试图实现的目标,因为ListView将自行处理滚动。例如:

<?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"
    >         

<TextView
android:id="@+id/question_label"    
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your question: "
/>     

<TextView
android:id="@+id/question"    
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>         

    <EditText  
        android:id="@+id/question_text"  
        android:layout_height="wrap_content"  
        android:hint="@string/question_comment_hint"  
        android:inputType="textMultiLine"  
        android:lines="4"  
        android:layout_width="fill_parent">  
    </EditText>

<Button  
        android:id="@+id/submit"  
        android:layout_height="wrap_content"  
        android:text="@string/submit"  
        android:onClick="sendFeedback"  
        android:layout_width="fill_parent">  
    </Button>       

<TextView
android:id="@+id/please_wait"    
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Please wait while the discussion loads..."
/>     

<ListView
android:id="@android:id/list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@+id/label"
    android:textSize="20px" >        
</ListView>         


现在的区别是,id为“please_wait”的文本视图不会随列表滚动。如果您需要滚动列表,我建议您在列表中使用java动态构建的TableLayout,然后将其和textview添加到滚动视图中。TableLayout不能单独滚动,这就是为什么它比在ScrollView中使用ListView更好的解决方案。如果您想这样做,请告诉我,我将发布一些示例代码。

我将完全取消scrollview-基于我认为您试图实现的目标,因为listview将自行处理滚动。例如:

<?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"
    >         

<TextView
android:id="@+id/question_label"    
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your question: "
/>     

<TextView
android:id="@+id/question"    
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>         

    <EditText  
        android:id="@+id/question_text"  
        android:layout_height="wrap_content"  
        android:hint="@string/question_comment_hint"  
        android:inputType="textMultiLine"  
        android:lines="4"  
        android:layout_width="fill_parent">  
    </EditText>

<Button  
        android:id="@+id/submit"  
        android:layout_height="wrap_content"  
        android:text="@string/submit"  
        android:onClick="sendFeedback"  
        android:layout_width="fill_parent">  
    </Button>       

<TextView
android:id="@+id/please_wait"    
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Please wait while the discussion loads..."
/>     

<ListView
android:id="@android:id/list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@+id/label"
    android:textSize="20px" >        
</ListView>         


现在的区别是,id为“please_wait”的文本视图不会随列表滚动。如果您需要滚动列表,我建议您在列表中使用java动态构建的TableLayout,然后将其和textview添加到滚动视图中。TableLayout不能单独滚动,这就是为什么它比在ScrollView中使用ListView更好的解决方案。如果您想这样做,请告诉我,我将发布一些示例代码。

基本上您可以这样做: 摆脱scrollview和加载textview。 为listview设置一个简单的适配器,如下所示:

fList = (ListView)findViewById(R.id.lstview);
fList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[]{"Please wait while the discussion loads..."}));

基本上你可以这样做: 摆脱scrollview和加载textview。 为listview设置一个简单的适配器,如下所示:

fList = (ListView)findViewById(R.id.lstview);
fList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[]{"Please wait while the discussion loads..."}));

滚动视图中不应包含ListView。 将线性布局(垂直)充气:

要填充线性布局,请执行以下操作:

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    for(int i = 0; i < comments.size(); i++){

        View childView = inflater.inflate(R.layout.comment_list_item, commentsLayout, false);

        TextView comment = (TextView) childView.findViewById(R.id.comment);

        comment.setText("Something");

        categoriesLayout.addView(childView, i);

    }
LayoutInflater充气器=(LayoutInflater)getSystemService(Context.LAYOUT\u充气器\u SERVICE);
对于(int i=0;i

诸如此类,希望这能有所帮助。

您不应该在ScrollView中包含ListView。 将线性布局(垂直)充气:

要填充线性布局,请执行以下操作:

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    for(int i = 0; i < comments.size(); i++){

        View childView = inflater.inflate(R.layout.comment_list_item, commentsLayout, false);

        TextView comment = (TextView) childView.findViewById(R.id.comment);

        comment.setText("Something");

        categoriesLayout.addView(childView, i);

    }
LayoutInflater充气器=(LayoutInflater)getSystemService(Context.LAYOUT\u充气器\u SERVICE);
对于(int i=0;i

诸如此类,希望这能有所帮助。

不确定这是否是问题所在,但在Android中,滚动视图中不应该有列表视图。@coder为什么会这样?你是对的。对我来说,不管我怎么做都会把事情搞砸。您将如何组织此类页面?listview的具体用途是什么?所有评论?@coder是的,列表就是评论列表。不确定这是否是问题所在,但在Android中,滚动视图中不应该有列表视图。@coder为什么会这样?你是对的。对我来说,不管我怎么做都会把事情搞砸。您将如何组织此类页面?listview的具体用途是什么?所有评论?@coder是的,列表就是评论列表。谢谢-现在让我试试。我知道嵌套的滚动视图给我带来了麻烦:)哦,是的,这完全奏效了!非常感谢。你绝对不辜负你的网名,还有一些!太好了,谢谢-让我试试这个。我知道嵌套的滚动视图给我带来了麻烦:)哦,是的,这完全奏效了!非常感谢。你绝对不辜负你的网名,还有一些!好极了。