Issue
I am new to the Android app development.
Now I am designing an app, in that I have an Activity which is containing some content. When the user change orientation to horizontal view, some content hide away (go out of screen). So to make then visible I want to add a scroll bar to my app.
Here is the code for my activity:
<?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:orientation="vertical"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
tools:context="com.example.nitin.justjava.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Toppings"
android:textAllCaps="true"/>
<CheckBox
android:id="@+id/whipped_cream_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Whipped cream"
android:textSize="16sp"
android:paddingLeft="24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="QUANTITY"
android:textAllCaps="true"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/b"
android:layout_width="48dp"
android:layout_height="48dp"
android:text="-"
android:onClick="decrement"
android:layout_marginRight="8dp"/>
<TextView
android:id="@+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="16sp"
android:textColor="#000000"
/>
<Button
android:id="@+id/a"
android:layout_width="48dp"
android:layout_height="48dp"
android:text="+"
android:onClick="increment"
android:layout_marginLeft="8dp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order Summary"
android:textAllCaps="true"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"/>
<TextView
android:id="@+id/order_summary_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rs. 0"
android:textSize="16sp"
android:textColor="#000000"
/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order"
android:layout_marginTop="16dp"
android:onClick="submitOrder"/>
</LinearLayout>
Thanks
Solution
ScrollView
may have only one direct child placed within it.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<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:orientation="vertical"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
tools:context="com.example.nitin.justjava.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Toppings"
android:textAllCaps="true"/>
<CheckBox
android:id="@+id/whipped_cream_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Whipped cream"
android:textSize="16sp"
android:paddingLeft="24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="QUANTITY"
android:textAllCaps="true"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/b"
android:layout_width="48dp"
android:layout_height="48dp"
android:text="-"
android:onClick="decrement"
android:layout_marginRight="8dp"/>
<TextView
android:id="@+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="16sp"
android:textColor="#000000"
/>
<Button
android:id="@+id/a"
android:layout_width="48dp"
android:layout_height="48dp"
android:text="+"
android:onClick="increment"
android:layout_marginLeft="8dp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order Summary"
android:textAllCaps="true"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"/>
<TextView
android:id="@+id/order_summary_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rs. 0"
android:textSize="16sp"
android:textColor="#000000"
/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order"
android:layout_marginTop="16dp"
android:onClick="submitOrder"/>
</LinearLayout>
</ScrollView>
Answered By - Vishal Yadav
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.