我正在尝试在ScrollView中使用ListView。目标是与其他应用程序类似的工作,例如Instagram和Facebook。下面的代码将是java中的代码和xml下的代码。如果我搞砸了语法,我道歉,因为我正在学习英语。
这是我的代码:
slImages = (SliderLayout)rootView.findViewById(R.id.slImageResource);
FSocietySlideView slideView = new FSocietySlideView(getContext());
slideView.image(R.mipmap.ic_launcher);
slideView.setOnSliderClickListener(HomeFragment.this);
slideView.description("None");
slImages.addSlider(slideView);
final ArrayList<FSociety> news = new ArrayList<>();
news.add(new FSociety(getResources(), "None", "None", R.mipmap.ic_launcher));
news.add(new FSociety(getResources(), "None", "None", R.mipmap.ic_launcher));
news.add(new FSociety(getResources(), "None", "None", R.mipmap.ic_launcher));
news.add(new FSociety(getResources(), "None", "None", R.mipmap.ic_launcher));
news.add(new FSociety(getResources(), "None", "None", R.mipmap.ic_launcher));
news.add(new FSociety(getResources(), "None", "None", R.mipmap.ic_launcher));
FSocietyAdapter adapter = new FSocietyAdapter(getActivity(),news);
ListView listView = (ListView)rootView.findViewById(R.id.list_test);
listView.setAdapter(adapter);
return rootView;
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#212121"
android:orientation="vertical">
<com.daimajia.slider.library.SliderLayout
android:id="@+id/slImageResource"
android:layout_width="match_parent"
android:layout_height="205dp"
android:layout_marginTop="0dp"
android:scaleType="fitXY" />
<com.daimajia.slider.library.Indicators.PagerIndicator
android:id="@+id/custom_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-4dp"
android:gravity="center"
custom:selected_color="#FFFFFF"
custom:selected_height="6dp"
custom:selected_padding_left="6dp"
custom:selected_padding_right="6dp"
custom:selected_width="6dp"
custom:shape="oval"
custom:unselected_color="#55333333"
custom:unselected_height="6dp"
custom:unselected_padding_left="2dp"
custom:unselected_padding_right="2dp"
custom:unselected_width="6dp" />
<ListView
android:id="@+id/list_test"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</LinearLayout>
答案 0 :(得分:0)
您永远不应该在ScrollView中放置ListView或RecyclerView。这会导致性能问题。 ListViews等自动处理滚动。
仅使用ScrollViews,例如,多个文本视图溢出屏幕。
答案 1 :(得分:0)
我不明白为什么要将listview放在scrollview中?如果我看看facebook app,则在scrollview中没有listview。如果我设计了facebook app,我会做那样的事情。
<LinearLayout> <-- Bottom layout
<LinearLayout>
//There are buttons for news, friends, etc
</LinearLayout>
<RecyclerView>
//There is your facebook news, which can scroll
//In recyclerview create custom item for showing one news
</RecyclerView>
</LinearLayout>
您可以在google上找到RecyclerView教程。