ともちゃんのAndroid開発日記

組込みC言語プログラマだったともちゃんが、四苦八苦しながら、AndroidのJAVA言語を習得して行きます。ともちゃんの備忘録も兼ねています。

Scroll View

Linear LayoutやRelative Layoutをスクロールするには、Scroll Viewを使います。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_weight="1">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.jimdo.uchida001tmhr.dietrecfree.DataMainFragment"
android:gravity="center_vertical">


<EditText
android:layout_width="80dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:inputType="number"
android:ems="10"
android:id="@+id/editTextYear"
android:layout_marginLeft="50dp"
android:layout_marginStart="50dp"
android:gravity="center_horizontal"
android:imeOptions="actionNext"
android:layout_alignTop="@+id/editTextDate"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<EditText
android:layout_width="55dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:inputType="number"
android:ems="10"
android:id="@+id/editTextMonth"
android:layout_alignBottom="@+id/editTextYear"
android:layout_toRightOf="@+id/editTextYear"
android:layout_toEndOf="@+id/editTextYear"
android:gravity="center_horizontal"
android:imeOptions="actionNext"/>

<EditText
android:layout_width="55dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:inputType="number"
android:ems="10"
android:id="@+id/editTextDate"
android:gravity="center_horizontal"
android:imeOptions="actionNext"
android:layout_below="@+id/buttonDayUp"
android:layout_toRightOf="@+id/editTextMonth"
android:layout_toEndOf="@+id/editTextMonth">
<requestFocus/>
</EditText>

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_up"
android:id="@+id/buttonYearUp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/editTextMonth"
android:layout_toStartOf="@+id/editTextMonth"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_up"
android:id="@+id/buttonMonthUp"
android:layout_alignTop="@+id/buttonYearUp"
android:layout_toRightOf="@+id/editTextYear"
android:layout_toEndOf="@+id/editTextYear"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="3dp" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_up"
android:id="@+id/buttonDayUp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/editTextMonth"
android:layout_toEndOf="@+id/editTextMonth"
android:layout_marginLeft="3dp" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_down"
android:id="@+id/buttonYearDown"
android:layout_below="@+id/editTextYear"
android:layout_alignLeft="@+id/buttonYearUp"
android:layout_alignStart="@+id/buttonYearUp"
android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_down"
android:id="@+id/buttonMonthDown"
android:layout_below="@+id/editTextMonth"
android:layout_alignLeft="@+id/editTextMonth"
android:layout_alignStart="@+id/editTextMonth"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="3dp" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_down"
android:id="@+id/buttonDayDown"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_above="@+id/editTextWeightValue"
android:layout_toRightOf="@+id/editTextMonth"
android:layout_toEndOf="@+id/editTextMonth"
android:layout_marginLeft="3dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/text_view_weight"
android:id="@+id/textViewWeight"
android:gravity="center_vertical"
android:layout_below="@+id/buttonYearDown"
android:layout_alignLeft="@+id/editTextYear"
android:layout_alignStart="@+id/editTextYear" />

<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/editTextWeightValue"
android:layout_alignTop="@+id/textViewWeight"
android:gravity="right"
android:layout_toRightOf="@+id/textViewBodyFatPercentage"
android:layout_toEndOf="@+id/textViewBodyFatPercentage"
android:singleLine="true"
android:inputType="numberDecimal"
android:imeOptions="actionNext"
>
<requestFocus/>
</EditText>

<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/text_view_weight_unit"
android:id="@+id/textViewWeightUnit"
android:layout_alignTop="@+id/editTextWeightValue"
android:layout_toRightOf="@+id/editTextWeightValue"
android:layout_toEndOf="@+id/editTextWeightValue"
android:layout_alignBottom="@+id/editTextWeightValue"
android:gravity="center_vertical" />

<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/text_view_body_fat_percentage"
android:id="@+id/textViewBodyFatPercentage"
android:layout_alignTop="@+id/editTextBodyFatPercentageValue"
android:layout_alignLeft="@+id/textViewWeight"
android:layout_alignStart="@+id/textViewWeight"
android:layout_alignBottom="@+id/editTextBodyFatPercentageValue"
android:gravity="center_vertical" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/editTextBodyFatPercentageValue"
android:layout_below="@+id/editTextWeightValue"
android:layout_alignLeft="@+id/editTextWeightValue"
android:layout_alignStart="@+id/editTextWeightValue"
android:gravity="right"
android:layout_toLeftOf="@+id/textViewWeightUnit"
android:layout_toStartOf="@+id/textViewWeightUnit"
android:singleLine="true"
android:inputType="numberDecimal"
android:imeOptions="actionNext"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/text_view_body_fat_percentage_init"
android:id="@+id/textViewBodyFatPercentageUnit"
android:layout_below="@+id/editTextWeightValue"
android:layout_toRightOf="@+id/editTextBodyFatPercentageValue"
android:layout_toEndOf="@+id/editTextBodyFatPercentageValue"
android:layout_alignBottom="@+id/editTextBodyFatPercentageValue"
android:gravity="center_vertical" />

<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/text_view_BMI"
android:id="@+id/textViewBMI"
android:layout_alignTop="@+id/editTextBMIValue"
android:layout_alignRight="@+id/textViewWeight"
android:layout_alignEnd="@+id/textViewWeight"
android:layout_alignBottom="@+id/editTextBMIValue"
android:gravity="center_vertical"
android:layout_toRightOf="@+id/textViewMemo"
android:layout_toEndOf="@+id/textViewMemo" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/editTextBMIValue"
android:gravity="right"
android:layout_below="@+id/editTextBodyFatPercentageValue"
android:layout_toLeftOf="@+id/textViewBodyFatPercentageUnit"
android:layout_alignLeft="@+id/editTextBodyFatPercentageValue"
android:layout_alignStart="@+id/editTextBodyFatPercentageValue"
android:singleLine="true"
android:inputType="numberDecimal"
android:editable="false"
android:imeOptions="actionNext"
android:focusable="false" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/check_box_O"
android:id="@+id/checkBox_O"
android:clickable="true"
android:layout_below="@+id/editTextBMIValue"
android:layout_alignLeft="@+id/buttonMonthDown"
android:layout_alignStart="@+id/buttonMonthDown" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/check_box_X"
android:id="@+id/checkBox_X"
android:textAppearance="?android:attr/textAppearanceLarge"
android:clickable="true"
android:layout_below="@+id/editTextBMIValue"
android:layout_alignRight="@+id/textViewWeightUnit"
android:layout_alignEnd="@+id/textViewWeightUnit" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/check_box_triangle"
android:id="@+id/checkBoxTriangle"
android:textAppearance="?android:attr/textAppearanceLarge"
android:clickable="true"
android:layout_below="@+id/checkBox_X"
android:layout_alignLeft="@+id/checkBox_O"
android:layout_alignStart="@+id/checkBox_O" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/check_box_star"
android:id="@+id/checkBoxStar"
android:textAppearance="?android:attr/textAppearanceLarge"
android:clickable="true"
android:layout_below="@+id/checkBox_X"
android:layout_alignLeft="@+id/checkBox_X"
android:layout_alignStart="@+id/checkBox_X" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/text_view_stamp"
android:id="@+id/textViewStamp"
android:gravity="center_vertical"
android:layout_above="@+id/editTextMemo"
android:layout_alignRight="@+id/textViewWeight"
android:layout_alignEnd="@+id/textViewWeight"
android:layout_alignTop="@+id/checkBox_O" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/text_view_memo"
android:id="@+id/textViewMemo"
android:layout_below="@+id/textViewStamp"
android:layout_alignLeft="@+id/textViewStamp"
android:layout_alignStart="@+id/textViewStamp"
android:layout_alignBottom="@+id/editTextMemo"
android:gravity="center_vertical" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:ems="10"
android:id="@+id/editTextMemo"
android:layout_below="@+id/checkBoxTriangle"
android:layout_toRightOf="@+id/textViewBMI"
android:layout_toEndOf="@+id/textViewBMI"
android:gravity="top|left"
android:imeOptions="actionDone"
android:singleLine="false" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_today"
android:id="@+id/buttonToday"
android:layout_alignBottom="@+id/editTextDate"
android:layout_toRightOf="@+id/textViewBodyFatPercentageUnit"
android:layout_toEndOf="@+id/textViewBodyFatPercentageUnit" />


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_data_main_register"
android:id="@+id/buttonDataMainRegister"
android:layout_below="@+id/textViewMemo"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_data_main_clear"
android:id="@+id/buttonDataMainClear"
android:layout_below="@+id/editTextMemo"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

</RelativeLayout>

</ScrollView>

 

 これで作成したViewがこちらです。

f:id:uchida001tmhr:20160423075651p:plain