我正在尝试使用其中的项创建一个简单的列表视图。我做了很多次,但这次由于某种原因,滚动不起作用。我使用基本适配器来显示项目,但它仍然无法正常工作。被困在这上面6个小时。任何帮助都将非常感激。片段中使用的ListView不会滚动。
具有列表视图的片段:
public class BlankFragment extends Fragment {
String[] itemsList = {"uguga", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "g", "h", "i", "j", "k"};
View mView;
ListView mListView;
ArrayAdapter<String> mAdapter;
public BlankFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_blank, container, false);
mListView = (ListView) mView.findViewById(R.id.newsFeedListView);
mAdapter = new ArrayAdapter<String>(getActivity().getBaseContext(), android.R.layout.simple_dropdown_item_1line, android.R.id.text1, itemsList);
mListView.setAdapter(mAdapter);
return mView;
}
}
fragment_blank.xml
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:divider="#000000"
android:id="@+id/newsFeedListView"
xmlns:android="http://schemas.android.com/apk/res/android"/>
activity_main.xml中
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/content_frame"
tools:context=".MainActivity" />
<ListView
android:layout_width="250dp"
android:layout_height="match_parent"
android:id="@+id/drawerItemsListView"/>
</android.support.v4.widget.DrawerLayout>
主要Activity.java
public class MainActivity extends ActionBarActivity {
DrawerLayout mDrawerLayout;
ListView mDrawerListView;
NewsFeedFragment mNewsFeedFragment;
ActionBar mActionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initReferences();
initFragments();
initProperties();
}
private void initProperties() {
mActionBar.setBackgroundDrawable(new ColorDrawable(0xFF326CBB));
}
private void initFragments() {
mNewsFeedFragment = NewsFeedFragment.newInstance();
getSupportFragmentManager().beginTransaction().add(R.id.content_frame, new BlankFragment()).commit();
}
private void initReferences() {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mDrawerListView = (ListView) findViewById(R.id.drawerItemsListView);
mActionBar = getSupportActionBar();
}
}
答案 0 :(得分:0)
将ListView
高度设置为"match_parent"
。
答案 1 :(得分:0)
好的。解决了这个问题。 MainActivity上的ListView正在进行所有输入操作,因为我没有为此指定重力。一旦我加入
android:layout_gravity="start"
到MainActivity ListView,我能够滚动。