我有一个带有很多项目的垂直可滚动布局,工作正常。
我正在尝试在屏幕底部放置一个新的线性布局,它不会成为可滚动布局的一部分。
也就是说,它将位于独立于可滚动部分的按钮上(如广告视图)。我只能将它放在滚动视图中。
我怎样才能把它放在下面,所以它总是可见的?
问问题
5594 次
4 回答
20
使用RelativeLayout,并像这样组织它:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_above="@+id/linearLayoutThatDoesNotScroll" >
<LinearLayout
android:id="@+id/linearLayoutWithLotofContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/linearLayoutThatDoesNotScroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
</LinearLayout>
</RelativeLayout>
诀窍在于 ScrollView 放置,同时它与屏幕顶部对齐,并且位于下部固定 LinearLayout 上方。它只是工作。
于 2011-11-30T14:39:02.357 回答
5
像这样的东西:)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView android:id="@+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>
<LinearLayout android:id="@+id/bottom"
android:layout_width="fill_parent"
android:layout_height="10dip" />
</LinearLayout>
您将使用 android:id=bottom 将底部内容添加到底部 linearLayout :)
于 2011-11-30T14:29:49.940 回答
1
如果您使用垂直LinearLayout
来保持可滚动布局,那么您可以将广告视图添加到LinearLayout
可滚动布局的下方,它会出现在屏幕底部。(假设您的权重设置正确,并且滚动布局设置为WRAP_CONTENT
)
ARelativeLayout
将允许您将 adview 设置为也与可滚动布局的底部对齐,但您仍需要确保可滚动布局设置为WRAP_CONTENT
不会自动占据整个屏幕。
于 2011-11-30T14:27:46.320 回答
1
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/dialogButtonOK"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text=" Ok "
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:background="@drawable/button_style"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:id="@+id/scrView"
android:layout_above="@id/dialogButtonOK"
android:layout_alignParentTop="true"
>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:id="@+id/main_table" >
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</RelativeLayout>
这对我有用
于 2015-08-02T12:39:00.203 回答