User Tools

Site Tools


android_learning:headfirst_android_development_notes:chapter_5

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
android_learning:headfirst_android_development_notes:chapter_5 [2016/01/24 03:43] mithatandroid_learning:headfirst_android_development_notes:chapter_5 [2016/01/24 04:45] (current) – [Additional notes] mithat
Line 88: Line 88:
 </WRAP> </WRAP>
  
-===== Additional notes =====+===== p. 219 ===== 
 +Your text suggest a ScrollView can be used as a root ViewGroup: 
 +<file xml content_main.xml> 
 +<?xml version="1.0" encoding="utf-8"?> 
 +<ScrollView 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:paddingBottom="@dimen/activity_vertical_margin" 
 +    android:paddingLeft="@dimen/activity_horizontal_margin" 
 +    android:paddingRight="@dimen/activity_horizontal_margin" 
 +    android:paddingTop="@dimen/activity_vertical_margin" 
 +    tools:context="com.hfad.scrollviewdemo.MainActivity" 
 +    tools:showIn="@layout/activity_main"> 
 + 
 +    <LinearLayout 
 +        android:layout_width="match_parent" 
 +        android:layout_height="wrap_content" 
 +        android:orientation="vertical"> 
 + 
 +        <TextView 
 +            android:layout_width="wrap_content" 
 +            android:layout_height="wrap_content" 
 +            android:text="Top!" /> 
 +         
 +        <TextView 
 +            android:layout_width="wrap_content" 
 +            android:layout_height="wrap_content" 
 +            android:text="Hello World!" /> 
 +        ... 
 + 
 +        <TextView 
 +            android:layout_width="wrap_content" 
 +            android:layout_height="wrap_content" 
 +            android:text="Bottom!" /> 
 +    </LinearLayout> 
 + 
 +</ScrollView> 
 + 
 +</file> 
 + 
 +However, in my experience this leads to unpredictable results (top of the ScrollView being obscured, etc.). A more reliable strategy seems to be nesting a ScrollView inside a root ViewGroups: 
 +<file xml content_main.xml> 
 +<?xml version="1.0" encoding="utf-8"?> 
 +<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" 
 +    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.hfad.scrollviewdemo.MainActivity" 
 +    tools:showIn="@layout/activity_main"> 
 + 
 +    <TextView 
 +        android:layout_width="wrap_content" 
 +        android:layout_height="wrap_content" 
 +        android:text="Outside ScrollView" 
 +        android:id="@+id/textView" /> 
 + 
 +    <ScrollView 
 +        android:layout_width="match_parent" 
 +        android:layout_height="match_parent" 
 +        android:id="@+id/scrollView" 
 +        android:layout_below="@+id/textView"> 
 + 
 +        <LinearLayout 
 +            android:layout_width="match_parent" 
 +            android:layout_height="wrap_content" 
 +            android:orientation="vertical"> 
 +             
 +            <TextView 
 +                android:layout_width="wrap_content" 
 +                android:layout_height="wrap_content" 
 +                android:text="Top" /> 
 + 
 +            <TextView 
 +                android:layout_width="wrap_content" 
 +                android:layout_height="wrap_content" 
 +                android:text="Hello World!" /> 
 +            ... 
 + 
 +            <TextView 
 +                android:layout_width="wrap_content" 
 +                android:layout_height="wrap_content" 
 +                android:text="Bottom" /> 
 +        </LinearLayout> 
 +    </ScrollView> 
 + 
 +</RelativeLayout> 
 +</file> 
 + 
 +Android Studio produces a warning stating that the ''android:layout_height'' attribute of the LinearLayout inside the ScrollView should be set to ''wrap_content'' rather than ''match_parent''
 + 
 +<WRAP center round info 90%> 
 +In the examples above, I am using string literals for the text attributes---only because this is throwaway, quick-n-dirty, prove-a-concept code. 
 +</WRAP> 
 + 
 + 
 +===== Additional notes on the UI builder =====
 If you examine the UI builder on a layout's "Design" tab, you will see that in addition to using it to add Views to your layout, you can also edit your Views' attributes. If you examine the UI builder on a layout's "Design" tab, you will see that in addition to using it to add Views to your layout, you can also edit your Views' attributes.
  
android_learning/headfirst_android_development_notes/chapter_5.1453607035.txt.gz · Last modified: 2016/01/24 03:43 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki