Java 为什么赢了';我的列表视图没有滚动?

Java 为什么赢了';我的列表视图没有滚动?,java,android,listview,scroll,Java,Android,Listview,Scroll,好吧,我看过其他有同样问题的帖子,但仍然不知道我做错了什么。这是我的密码: ListView list = (ListView) getView().findViewById(R.id.listView); String[] stringArray = new String[] { "Bright Mode", "Normal Mode","Bright Mode", "hey Mode","Bright Mode", "Normal Mode","Bright

好吧,我看过其他有同样问题的帖子,但仍然不知道我做错了什么。这是我的密码:

ListView list = (ListView) getView().findViewById(R.id.listView);
    String[] stringArray = new String[] { "Bright Mode", "Normal Mode","Bright Mode",
            "hey Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","Bright Mode",
            "hey Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","Bright Mode",
            "hey Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","Bright Mode",
            "hey Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","end", "Bright Mode", "Normal Mode","Bright Mode",
            "hey Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode", "end2" };
    ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(getView().getContext(), R.layout.document_list_view, stringArray);
    list.setAdapter(modeAdapter);
    list.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {

            Toast.makeText(getView().getContext(), "Clicked", Toast.LENGTH_LONG).show();

        }
    }); 
ListView列表=(ListView)getView().findViewById(R.id.ListView);
字符串[]stringArray=新字符串[]{“亮模式”、“正常模式”、“亮模式”,
“hey模式”、“Bright模式”、“Normal模式”、“Bright模式”、“Normal模式”、“Bright模式”、“Normal模式”、“Bright模式”,
“hey模式”、“Bright模式”、“Normal模式”、“Bright模式”、“Normal模式”、“Bright模式”、“Normal模式”、“Bright模式”,
“hey模式”、“Bright模式”、“Normal模式”、“Bright模式”、“Normal模式”、“Bright模式”、“Normal模式”、“Bright模式”,
“嘿模式”、“亮模式”、“正常模式”、“亮模式”、“正常模式”、“结束”、“亮模式”、“正常模式”、“亮模式”,
“hey模式”、“Bright模式”、“Normal模式”、“Bright模式”、“Normal模式”、“end2”};
ArrayAdapter modeAdapter=新的ArrayAdapter(getView().getContext(),R.layout.document\u list\u view,stringArray);
list.setAdapter(modeAdapter);
list.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
公共视图单击(适配器视图a、视图v、内部位置、长id){
Toast.makeText(getView().getContext(),“单击”,Toast.LENGTH_LONG.show();
}
}); 
点击效果很好,但内容会离开屏幕,不允许我滚动。这是我的XML。它不在scrollview或任何东西中

文档列表视图:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
    android:id="@+id/listText"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_height="wrap_content"
    android:checkMark="?android:attr/listChoiceIndicatorSingle"
    android:textColor="@color/black">


</TextView>

页面布局:

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

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ListView>



</LinearLayout>

将页面布局更改为仅与其父视图(在本例中为窗口装饰)大小匹配的列表视图

<ListView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</ListView>

如果要为每个列表项使用自定义视图,则需要为列表视图使用自定义适配器。你需要这样的东西

public class CustomAdapter extends ArrayAdapter<String>{
List<String> items;
....
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    if (v == null) {
        LayoutInflater vi = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.document_list_view, null);
    }

    String item = (String) items.get(position);

    if (item != null) {
        TextView text= (TextView) v.findViewById(R.id.listText);
        if (text!= null) {
            text.setText(item);
        }
    }
    return v;
}
公共类CustomAdapter扩展了ArrayAdapter{
清单项目;
....
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图v=转换视图;
如果(v==null){
LayoutInflater vi=(LayoutInflater)上下文
.getSystemService(上下文布局\充气机\服务);
v=vi.充气(R.布局.文件列表视图,空);
}
stringitem=(String)items.get(position);
如果(项!=null){
TextView text=(TextView)v.findViewById(R.id.listText);
如果(文本!=null){
text.setText(项目);
}
}
返回v;
}

并将此对象设置为列表的适配器。

发现此问题,是因为我扩展了一个类,该类将所有内容都放在scrollview中。不要将listview放在scrollview中。

能否为您的问题添加一个屏幕截图?imgur链接或类似的图像宿主链接也可以。listview的屏幕截图?看不到太多。内容显示正确,但不可滚动。listview位于一个弹出窗口内,该弹出窗口将填充屏幕。为什么要使用1000dp和600dp?请同时使用match_parent!您的类是否扩展了
片段的
活动
?如果我这样做,它将变为空白。可能它没有正确膨胀?您是否为它设置了值特快专递名单?