I have a layout with scrollview:
<?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"
android:fadingEdge="none"
android:overScrollMode="never"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="100"
android:background="@color/antiquewhite">
<LinearLayout
android:id="@+id/top_layou"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="15"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="25dp"
android:background="@color/bisque">
<TextView
android:id="@+id/title_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="15dp"
android:text="@string/user_information_text"
android:textSize="26dp"
android:textStyle="bold"
android:textColor="@color/black" />
<TextView
android:id="@+id/subtitle_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
android:text="@string/user_information_subtitle_text"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@color/black"/>
</LinearLayout>
<LinearLayout
android:id="@+id/body_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="85"
android:orientation="horizontal"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:weightSum="100"
>
<LinearLayout
android:id="@+id/left_part"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="50"
android:weightSum="100"
android:background="@color/antiquewhiter">
<TextView
android:id="@+id/first_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="30dp"
android:text="@string/first_name_text"
style="@style/bold_text18"
/>
<LinearLayout
android:id="@+id/first_name_edit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<EditText
android:id="@+id/first_name_edit_text"
style="@style/editTextsvCard"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
android:layout_weight="90"
android:ems="10"
>
</EditText>
</LinearLayout>
<TextView
android:id="@+id/company_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="30dp"
android:text="@string/company_text"
style="@style/bold_text18" />
<LinearLayout
android:id="@+id/company_edit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<EditText
android:id="@+id/company_edit_text"
style="@style/editTextsvCard"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
android:layout_weight="90"
android:ems="10"
>
</EditText>
</LinearLayout>
<TextView
android:id="@+id/phone_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="30dp"
android:text="@string/phone_text"
style="@style/bold_text18"/>
<LinearLayout
android:id="@+id/phone_edit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<EditText
android:id="@+id/phone_edit_text"
style="@style/editTextsvCard"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
android:layout_weight="90"
android:ems="10"
android:inputType="phone"
>
</EditText>
</LinearLayout>
<TextView
android:id="@+id/e_mail_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="30dp"
android:text="@string/e_mail_text"
style="@style/bold_text18" />
<LinearLayout
android:id="@+id/e_mail_edit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<EditText
android:id="@+id/e_mail_edit_text"
style="@style/editTextsvCard"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
android:layout_weight="90"
android:ems="10"
android:inputType="textEmailAddress"
>
</EditText>
</LinearLayout>
<TextView
android:id="@+id/mobile_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="30dp"
android:text="@string/mobile_text"
style="@style/bold_text18"/>
<LinearLayout
android:id="@+id/mobile_edit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<EditText
android:id="@+id/mobile_edit_text"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
style="@style/editTextsvCard"
android:layout_weight="90"
android:ems="10"
>
</EditText>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/right_part"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="50"
android:paddingRight="40dp"
android:orientation="vertical"
android:weightSum="100"
android:background="@color/antiquewhiter">
<TextView
android:id="@+id/last_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="30dp"
android:text="@string/last_name_text"
style="@style/bold_text18" />
<LinearLayout
android:id="@+id/last_name_edit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<EditText
android:id="@+id/last_name_edit_text"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
android:layout_weight="100"
android:ems="10"
style="@style/editTextsvCard"
>
</EditText>
</LinearLayout>
<TextView
android:id="@+id/position_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="30dp"
android:text="@string/position_text"
style="@style/bold_text18"/>
<LinearLayout
android:id="@+id/position_edit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<EditText
android:id="@+id/position_edit_text"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
android:layout_weight="100"
android:ems="10"
style="@style/editTextsvCard"
>
</EditText>
</LinearLayout>
<TextView
android:id="@+id/fax_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="30dp"
android:text="@string/fax_text"
style="@style/bold_text18"/>
<LinearLayout
android:id="@+id/fax_edit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<EditText
android:id="@+id/fax_edit_text"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
android:layout_weight="100"
android:ems="10"
android:inputType="phone"
style="@style/editTextsvCard"
>
</EditText>
</LinearLayout>
<TextView
android:id="@+id/internet_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="30dp"
android:text="@string/internet_text"
style="@style/bold_text18"/>
<LinearLayout
android:id="@+id/internet_edit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<EditText
android:id="@+id/internet_edit_text"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
android:layout_weight="100"
android:ems="10"
style="@style/editTextsvCard"
>
</EditText>
</LinearLayout>
<TextView
android:id="@+id/b_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="30dp"
android:text="@string/internet_text"
style="@style/bold_text18"
android:visibility="invisible"
/>
<LinearLayout
android:id="@+id/button_edit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:layout_gravity="right"
android:gravity="right">
<Button
android:id="@+id/speichern_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="70dp"
android:layout_weight="40"
android:text="@string/speichern_text"
>
</Button>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Vertical view work perfect but I would like to know if I can add horizontal scroll to this layout because when I have horizontal orientation layout looks good but when I change orientation I don't want to reduce size some elements in layout. I think about add horizontal scrool. This is possible?
ScrollView is used to scroll the child elements of palette inside ScrollView. Android supports vertical scroll view as default scroll view. Vertical ScrollView scrolls elements vertically. Android uses HorizontalScrollView for horizontal ScrollView.
ScrollView and HorizontalScrollView has same attributes, the only difference is scrollView scroll the child items in vertical direction while horizontal scroll view scroll the child items in horizontal direction.
I add:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
as child my scroll view and this solution works great.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With