Reputation: 383
I'm attempting to create a simple image gallery with the thumbnails shown at the bottom using a RecyclerView and the large/detailed photo shown above it in an ImageView.
The problem is - the RecyclerView with the thumbnails is shown and created - however the large/detailed image is never shown, even when hardcoding it's background. I believe this to be an XML related issue - but I cannot seem to spot the problem.
Any suggestions are appreciated.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/black_color"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MMSGallery">
<ImageView
android:id="@+id/detail_photo"
android:background="@drawable/mms_img1"
android:adjustViewBounds="true"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:layout_margin="2dp"
android:layout_width="match_parent"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_images"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignStart="@+id/detail_photo"
android:background="@color/black_color" />
</RelativeLayout>
public class SpaceGalleryActivity extends AppCompatActivity {
ImageView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_space_gallery);
mImageView = (ImageView) findViewById(R.id.detail_photo);
Glide.with(this)
.load("http://i.imgur.com/zuG2bGQ.jpg")
.placeholder(R.drawable.ic_launcher)
.into(mImageView);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, 2);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv_images);
recyclerView.setHasFixedSize(true);
// recyclerView.setLayoutManager(layoutManager);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
SpaceGalleryActivity.ImageGalleryAdapter adapter = new SpaceGalleryActivity.ImageGalleryAdapter(this, SpacePhoto.getSpacePhotos());
recyclerView.setAdapter(adapter);
}
....
Upvotes: 0
Views: 57
Reputation: 383
Changing from a RelativeLayout
to a LinearLayout
resolved the issue.
Upvotes: 0
Reputation: 2432
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MMSGallery">
<ImageView
android:id="@+id/detail_photo"
android:background="@mipmap/ic_launcher"
android:adjustViewBounds="true"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:layout_margin="2dp"
android:layout_width="match_parent"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_images"
android:layout_below="@+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_color" />
</RelativeLayout>
Upvotes: 0
Reputation: 7944
It would work for you.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black">
<ImageView
android:id="@+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:adjustViewBounds="true"
android:background="@drawable/placeholder"
android:scaleType="centerCrop" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_images"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/detail_photo"
android:background="@color/red_500" />
Upvotes: 1
Reputation: 2355
the problem is that you are setting RecyclerView
to match_parent
.which overlaps your ImageView
so change your layout to
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="2dp"
android:adjustViewBounds="true"
android:background="@drawable/mms_img1"
android:scaleType="centerCrop" />
<android.support.v7.widget.RecyclerView
android:layout_marginTop="28dp"
android:id="@+id/rv_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/detail_photo"
android:layout_below="@id/detail_photo"
android:background="@color/black_color"
/>
</RelativeLayout>
Upvotes: 1