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 trialBen Rebecca
3,055 PointsUsing PercentRelativeLayout in older APIs (Android)
Hi all,
I'm experimenting with Percent Relative Layout which is helping me create a dynamically resizing layout appropriate on screens of any size.
It looks perfect on an emulator, but when I try to run the app on my phone (running API 16 or so, android 4) nothing but textviews show up. ImageViews, Buttons and everything else does not show.
The emulator seems to work back to API 16 as does the render preview. I have no idea why it won't work on the phone.
Here's what I'm working with below. Any help is appreciated! Thank you :)
<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="fill_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.y"
tools:showIn="@layout/app_bar_main"
android:background="#FFF"
android:weightSum="1"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView"
android:scrollIndicators="top">
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="This text appears correctly"
android:textSize="28sp"
android:id="@+id/textMainTitle"
android:layout_gravity="center"
android:layout_alignParentTop="true"
android:textColor="#ffffff"
android:singleLine="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="As does this text"
android:id="@+id/textMainSubTitle"
android:layout_gravity="center_horizontal"
android:layout_below="@id/textMainTitle"
/>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/btnIntro"
android:src="@drawable/button1" //DOES NOT APPEAR IN PHONE
app:layout_widthPercent="30%"
app:layout_heightPercent="25%"
android:layout_below="@id/textMainSubTitle"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp" />
</android.support.percent.PercentRelativeLayout>
</ScrollView>
</LinearLayout>