Ich versuche, GUI für eine App in Android machen Ich bin Anfänger in diesem.Add DividerItemDecoration beide Seiten von RecyclerView
Zuerst mache ich eine horizontale recyclerView
, fügen DividerItemDecoration
mit einem benutzerdefinierten Zeichen und Setup LinearSnapHelper
für immer Snap in der Mitte.
Es funktioniert, aber die linke Seite ist neben der Seite des Bildschirms, weil dividerItemDecorator
nur die Linie zwischen Elementen setzen.
Exists jede mögliche Weise Teiler am Anfang der recycler
zu setzen, ich habe etwas Padding oder Margin setzen versucht, aber wenn ich es schieben „schneidet“, bevor das Ende des Bildschirms
Leider erreichen in vorzurücken für die englische
Mein Code
MainActivity ist
@BindView(R.id.rvRecentNews)
RecyclerView rvRecentNews;
private ArrayList<String> horizontalList;
private HorizontalAdapter horizontalAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
ButterKnife.bind(this);
horizontalList=new ArrayList<>();
horizontalList.add("horizontal 1");
horizontalList.add("horizontal 2");
horizontalList.add("horizontal 3");
horizontalList.add("horizontal 4");
horizontalList.add("horizontal 5");
horizontalList.add("horizontal 6");
horizontalList.add("horizontal 7");
horizontalList.add("horizontal 8");
horizontalList.add("horizontal 9");
horizontalList.add("horizontal 10");
horizontalAdapter=new HorizontalAdapter(horizontalList);
LinearLayoutManager horizontalLayoutManagaer
= new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
rvRecentNews.setLayoutManager(horizontalLayoutManagaer);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(rvRecentNews.getContext(),
horizontalLayoutManagaer.getOrientation());
dividerItemDecoration.setDrawable(getApplicationContext().getResources().getDrawable(R.drawable.line_divider));
rvRecentNews.addItemDecoration(dividerItemDecoration);
SnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(rvRecentNews);
rvRecentNews.setAdapter(horizontalAdapter);
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:orientation="vertical"
tools:context="com.sgd.pawfriends.MainActivity"
tools:showIn="@layout/app_bar_main">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_marginTop="8dp"
android:id="@+id/rvRecentNews"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="salir"
android:onClick="logout"
/>
</LinearLayout>
Vielen Dank im Voraus
Sie benutzerdefinierte erstellen müssen erstellen 'ItemDecoration' –