如何将滚动视图放到多个线性布局中?
How to put a scroll view to many linear layout?
我设计了这个用户界面,因为它不会显示整个 activity 我想将滚动视图放在 layout.When 我在滚动视图中放入一些按钮位置 changes.how我可以更改吗?
XML代码:
<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>
对不起,如果我没有得到你,但我想这就是你需要的...
<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>
希望对您有所帮助:)
<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>
您必须为 ScrollView
设置固定大小。在XML
中或者计算其中所有children的身高,然后求和并设置为ScrollView
。
只需将要滚动的视图(布局)放入 <scrollView> </scrollView>
标记内即可。
将滚动视图标签放在视图顶部(列表视图、线性...等)
使其宽度/高度与父级匹配
这里是例子
<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>
我设计了这个用户界面,因为它不会显示整个 activity 我想将滚动视图放在 layout.When 我在滚动视图中放入一些按钮位置 changes.how我可以更改吗?
XML代码:
<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>
对不起,如果我没有得到你,但我想这就是你需要的...
<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>
希望对您有所帮助:)
<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>
您必须为 ScrollView
设置固定大小。在XML
中或者计算其中所有children的身高,然后求和并设置为ScrollView
。
只需将要滚动的视图(布局)放入 <scrollView> </scrollView>
标记内即可。
将滚动视图标签放在视图顶部(列表视图、线性...等)
使其宽度/高度与父级匹配
这里是例子
<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>