[英]Scroll View in Relative Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1E1E1E"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:weightSum="1" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="@+id/button7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ld"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="Button 3"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:weightSum="1" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ld"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:singleLine="false"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ld"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:singleLine="false"
android:text="Botton 2"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:weightSum="1" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ld"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="Button 3"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ld"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="Button 4"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:weightSum="1" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ld"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="Button 5"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="Button 6"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:background="#fff"
android:weightSum="6" >
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@id/b1"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="@drawable/home1"
android:text="Home"
android:textSize="8dp" />
<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/b2"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="@drawable/abt"
android:text="About"
android:textSize="8dp" />
<Button
android:id="@+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/b3"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="@drawable/ser"
android:text="Services"
android:textSize="8dp" />
<Button
android:id="@+id/b4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/b4"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="@drawable/cnt1"
android:text="Portfolio"
android:textSize="8dp" />
<Button
android:id="@+id/b5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/b5"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="@drawable/spt"
android:text="Support"
android:textSize="8dp" />
<Button
android:id="@+id/b6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/b6"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="@drawable/inbox"
android:text="Marketing"
android:textSize="8dp" />
</LinearLayout>
</RelativeLayout>
我需要在页脚固定的相对布局中使用滚动视图。 仅表格布局应具有滚动视图,页脚应固定
将滚动视图添加为TableLayout的父级,并将其在底部布局上方对齐。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1E1E1E" >
<LinearLayout
android:id="@+id/bottombar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:background="#fff"
android:weightSum="6" >
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@id/b1"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="@drawable/home1"
android:text="Home"
android:textSize="8dp" />
<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/b2"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="@drawable/abt"
android:text="About"
android:textSize="8dp" />
<Button
android:id="@+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/b3"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="@drawable/ser"
android:text="Services"
android:textSize="8dp" />
<Button
android:id="@+id/b4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/b4"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="@drawable/cnt1"
android:text="Portfolio"
android:textSize="8dp" />
<Button
android:id="@+id/b5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/b5"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="@drawable/spt"
android:text="Support"
android:textSize="8dp" />
<Button
android:id="@+id/b6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/b6"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="@drawable/inbox"
android:text="Marketing"
android:textSize="8dp" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/bottombar" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:weightSum="1" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="@+id/button7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ld"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="Button 3"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:weightSum="1" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ld"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:singleLine="false"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ld"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:singleLine="false"
android:text="Botton 2"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:weightSum="1" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ld"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="Button 3"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ld"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="Button 4"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:weightSum="1" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ld"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="Button 5"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="Button 6"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
将其用作顶层,并添加所需的内容:
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:weightSum="1"
tools:context=".MainActivityFragment">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TableLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1"
android:orientation="horizontal"
android:id="@+id/footer">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
在给定的xml代码中,添加滚动视图并替换其中的TableLayout。 这样,让它成为第一个布局。
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1E1E1E">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
//contents inside table layout
</TableLayout>
</ScrollView>
</RelativeLayout>
现在创建另一个页脚布局,像这样,让它成为第二个布局。
<RelativeLayout>
//things to be appeared on footer are added here
</RelativeLayout>
在您的Java代码中,使用它们的ID获取两个布局,将第二个布局设置为第一个布局的页脚。
firstlayout.addFooterView(secondlayout);
现在,您可以获得固定的页脚,并且仅在第一个layouts表布局中滚动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.