簡體   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