RecyclerView Raster-Layout-Manager Zentrum nicht Artikel
ich etwas großes Projekt mit einer Menge von Legacy-Code geerbt und nun einige seltsame Sachen, die ich bin vor ..
Ich brauche diesen Bildschirm zu machen Recyclerview mit Grid Layout Manager, 2 Spalten. Das ist was ich bekomme. Gibt es eine Möglichkeit, diese Symbole in der Mitte des Bildschirms zu zentrieren? Ich habe es mit der Schwerkraft versucht, aber nichts funktioniert. Vielleicht gibt es irgendwas in diesem alten Code, der Probleme verursacht, oder das ist nur das Problem von recyclerView?
Dies ist das Layout des Artikels (schrecklich, fragen Sie nicht ..)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_view_controller_item_background"
android:orientation="vertical">
<TextView
android:id="@+id/textViewSceneKK"
android:layout_width="match_parent"
android:layout_height="@dimen/room_button_height"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/row_filter_text_margin_left"
android:layout_marginRight="@dimen/row_filter_text_margin_left"
android:gravity="center"
android:shadowDx="-1"
android:shadowDy="-1"
android:shadowRadius="1"
android:textSize="@dimen/row_scene_kk_text_size" />
<TextView
android:id="@+id/textViewSceneName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/row_filter_text_margin_bottom"
android:layout_marginLeft="@dimen/row_filter_text_margin_left"
android:layout_marginRight="@dimen/row_filter_text_margin_left"
android:layout_marginTop="@dimen/row_filter_text_margin_top"
android:clickable="false"
android:gravity="center"
android:longClickable="false"
android:textColor="@color/main_text_color"
android:textSize="@dimen/row_browser_right_name_text_size" />
</LinearLayout>
<!--<View-->
<!--android:id="@+id/filterView"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:clickable="false"-->
<!--android:longClickable="false" />-->
<View
android:id="@+id/filterViewClick"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:selectableItemBackground"
android:focusable="false"
android:focusableInTouchMode="false" />
Und fragment't Layout:
<customview.CustomRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none" />
und den Code:
customRecyclerView.setHasFixedSize(false);
customRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
customRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(),
R.drawable.line_separator_empty, DividerItemDecoration.VERTICAL_LIST));
customRecyclerView.setAdapter(adapter);
CustomRecyclerView.java
public class CustomRecyclerView extends RecyclerView {
private boolean enableScroll = true;
public CustomRecyclerView(Context context) {
super(context);
}
public CustomRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomRecyclerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public boolean isEnableScroll() {
return enableScroll;
}
public void setEnableScroll(boolean enableScroll) {
this.enableScroll = enableScroll;
}
@Override
public int computeVerticalScrollRange() {
return super.computeVerticalScrollRange();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
if (enableScroll) {
return super.onInterceptTouchEvent(e);
}
return false;
}
}
Zeige XML und Code. Überprüfen Sie RecyclerView Breite muss _match_parent_ – Piyush
zeigen Sie einige Code-und die Recyclerview mit Layout – Pavan
Make _customRecyclerView.setHasFixedSize (true); _ Auch zeigen _CustomRecyclerView_ Klasse – Piyush