我需要有关如何删除网格布局内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 );
}
}
答案 0 :(得分:2)
删除
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">