繁体   English   中英

删除GridLayout内部cardview之间的空白

[英]Remove empty spaces between cardviews inside GridLayout

我需要有关如何删除网格布局内cardViews之间的空白的帮助。 卡的每一行下方都是空白区域。我要删除此多余的空间。如何解决此问题。我提供了一个屏幕截图来阐明这一点。

这是我的布局XML代码

 <android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_below="@+id/toolbar"
    android:layout_marginTop="50dp"
    android:paddingBottom="0dp"
    app:contentPaddingLeft="0dp"
    app:contentPaddingRight="0dp"
    app:contentPaddingTop="0dp"
    app:cardUseCompatPadding="true"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <TextView
           android:paddingTop="2dp"
            android:id="@+id/text_view_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="name"
            android:textSize="11sp"
            android:textAlignment="center" />


        <ImageView
            android:transitionName="@+id/profile"
            android:layout_marginTop="10dp"
            android:layout_below="@+id/text_view_name"
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:id="@+id/image_view_upload"
            android:adjustViewBounds="true"
            android:clickable="false"
            android:focusable="false"/>

    </RelativeLayout>

    </android.support.v7.widget.CardView>

我的MainActivity布局

<RelativeLayout 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"
    tools:context=".MainActivity">

    <android.support.v7.widget.RecyclerView
        android:layout_marginTop="80dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/recycler_view"
        android:background="#000000"
        android:clipToPadding="false"/>
</RelativeLayout>




我的java MainActivity类

public class MainActivity extends AppCompatActivity implements ImageAdapter.OnItemClickListener {

 private RecyclerView recyclerview;
private ImageAdapter adapter;

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

  recyclerview = (RecyclerView) findViewById(R.id.recycler_view);
        adapter = new ImageAdapter(this, uploads);

  recyclerview.setLayoutManager(new GridLayoutManager(this,3));
     recyclerview.setPadding ( 1,1,1,1 );
}
}

这是截图

去掉

android:layout_marginTop="50dp"

从您的CardView

<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_below="@+id/toolbar"
android:paddingBottom="0dp"
app:contentPaddingLeft="0dp"
app:contentPaddingRight="0dp"
app:contentPaddingTop="0dp"
app:cardUseCompatPadding="true"
android:orientation="vertical">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM