Reputation: 65
I have designed this User Interface since it wont show the whole activity I want to put a scrollview to the layout.When I put in to a scroll view some buttons postion changes.how can I change it?
XML Code:
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="#3697dc"
android:weightSum="1">
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#3697dc"
>
<Button
android:id="@+id/TextView1"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/polonnaruwa"
android:layout_margin="5dp"
/>
<Button
android:id="@+id/TextView2"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/anuradhapura"
android:layout_margin="5dp"
/>
<Button
android:id="@+id/TextView3"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/dambulla"
android:layout_margin="5dp"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#3697dc"
android:layout_gravity="bottom">
<Button
android:id="@+id/textView2"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="0.5"
android:background="@drawable/kandy"
android:layout_margin="5dp" />
<Button
android:id="@+id/textView"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="0.24"
android:background="@drawable/trincomalee"
android:layout_margin="5dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#3697dc"
android:layout_gravity="center_horizontal">
<Button
android:id="@+id/textView3"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="0.24"
android:background="@drawable/galle"
android:layout_margin="5dp" />
<Button
android:id="@+id/textView4"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="0.5"
android:background="@drawable/colombo"
android:layout_margin="5dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#3697dc"
android:layout_gravity="center_horizontal">
<Button
android:id="@+id/textView5"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/hikkaduwa"
android:layout_margin="5dp" />
<Button
android:id="@+id/textView6"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/yala"
android:layout_margin="5dp" />
<Button
android:id="@+id/textView7"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/bentota"
android:layout_margin="5dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#3697dc"
android:layout_gravity="center_horizontal" >
<Button
android:id="@+id/textView9"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="0.5"
android:background="@drawable/nuwaraeliya"
android:layout_margin="5dp" />
<Button
android:id="@+id/textView8"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="0.24"
android:background="@drawable/ratnapura"
android:layout_margin="5dp" />
</LinearLayout>
<ScrollView
android:layout_weight="0.10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
>
</ScrollView>
</LinearLayout>
Upvotes: 1
Views: 996
Reputation: 21452
Put scroll View tag in the top of your views (listviews , linear ...etc)
make it width / height match parent
here is Example
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="@+id/GlobalLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView android:id="@+id/ListView1"
android:choiceMode="multipleChoice"
android:layout_height="100dip"
android:layout_width="fill_parent" />
<ListView android:id="@+id/ListView2"
android:choiceMode="multipleChoice"
android:layout_height="100dip"
android:layout_width="fill_parent" />
<ListView android:id="@+id/ListView3"
android:choiceMode="multipleChoice"
android:layout_height="100dip"
android:layout_width="fill_parent" />
</LinearLayout>
</ScrollView>
Upvotes: 0
Reputation: 7901
Just put the view (layout) you want to scroll inside <scrollView> </scrollView>
tag.
Upvotes: 1
Reputation: 1266
You must set fixed size to your ScrollView
. In XML
or calculate the height of all childrens in it, then sum and set to ScrollView
.
Upvotes: 0
Reputation: 188
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="#3697dc"
android:weightSum="1">
<ScrollView
android:layout_weight="0.10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
>
<Relative Layout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#3697dc"
>
<Button
android:id="@+id/TextView1"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/polonnaruwa"
android:layout_margin="5dp"
/>
<Button
android:id="@+id/TextView2"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/anuradhapura"
android:layout_margin="5dp"
/>
<Button
android:id="@+id/TextView3"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/dambulla"
android:layout_margin="5dp"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#3697dc"
android:layout_gravity="bottom">
<Button
android:id="@+id/textView2"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="0.5"
android:background="@drawable/kandy"
android:layout_margin="5dp" />
<Button
android:id="@+id/textView"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="0.24"
android:background="@drawable/trincomalee"
android:layout_margin="5dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#3697dc"
android:layout_gravity="center_horizontal">
<Button
android:id="@+id/textView3"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="0.24"
android:background="@drawable/galle"
android:layout_margin="5dp" />
<Button
android:id="@+id/textView4"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="0.5"
android:background="@drawable/colombo"
android:layout_margin="5dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#3697dc"
android:layout_gravity="center_horizontal">
<Button
android:id="@+id/textView5"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/hikkaduwa"
android:layout_margin="5dp" />
<Button
android:id="@+id/textView6"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/yala"
android:layout_margin="5dp" />
<Button
android:id="@+id/textView7"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/bentota"
android:layout_margin="5dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#3697dc"
android:layout_gravity="center_horizontal" >
<Button
android:id="@+id/textView9"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="0.5"
android:background="@drawable/nuwaraeliya"
android:layout_margin="5dp" />
<Button
android:id="@+id/textView8"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="0.24"
android:background="@drawable/ratnapura"
android:layout_margin="5dp" />
</LinearLayout>
</Relative Layout>
</ScrollView>
</LinearLayout>
Upvotes: 0
Reputation: 238
I am sorry If I don't get you, but I think this is what you need...
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3697dc"
android:orientation="vertical"
android:weightSum="1"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3697dc"
android:orientation="horizontal" >
<Button
android:id="@+id/TextView1"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="polonnaruwa" />
<Button
android:id="@+id/TextView2"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="anuradhapura" />
<Button
android:id="@+id/TextView3"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="dambulla" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#3697dc"
android:orientation="horizontal" >
<Button
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="0.5"
android:text="kandy" />
<Button
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="0.24"
android:text="trincomalee" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#3697dc"
android:orientation="horizontal" >
<Button
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="0.24"
android:text="galle" />
<Button
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="0.5"
android:text="colombo" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#3697dc"
android:orientation="horizontal" >
<Button
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="hikkaduwa" />
<Button
android:id="@+id/textView6"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="yala" />
<Button
android:id="@+id/textView7"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="bentota" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#3697dc"
android:orientation="horizontal" >
<Button
android:id="@+id/textView9"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="0.5"
android:text="nuwaraeliya" />
<Button
android:id="@+id/textView8"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="0.24"
android:text="ratnapura" />
</LinearLayout>
</LinearLayout></ScrollView>
Hope it helps :)
Upvotes: 2