Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLuke Cusack
382 PointsListView items are spaced 1 screen apart (in height)
My items (image of recipe + text of recipe) are spaced 1 screen apart. The first appears at the top of the screen, and then the 2nd appears below my screen until I scroll down, and so on.
Here is my code for the views, which I've checked follows the videos tutorials:
activity_mail.xml:
<?xml version="1.0" encoding="utf-8"?>
<!--using framelayout-->
<FrameLayout 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:id="@+id/placeHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hello.treehousesmellslikebakin.MainActivity">
</FrameLayout>
fragment_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
<android.support.v7.widget.RecyclerView
android:id="@+id/listRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/itemImage"
android:layout_width="0dp"
android:layout_height="50dp"
android:scaleType="fitCenter"
android:layout_margin="8dp"
android:layout_weight="1" />
<TextView
android:id="@+id/itemText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_margin="12dp"
android:textSize="24sp"
android:text="TextView" />
</LinearLayout>
Have I missed something or got something wrong? Thanks!
1 Answer
Luke Cusack
382 PointsOk I've found the problem, thanks to this post: https://teamtreehouse.com/community/listitemxml-layout
In list_item.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
Before I had android:layout_height
set to "match_parent".
This problem is solved.