【发布时间】:2012-09-04 17:45:41
【问题描述】:
我想放大一些视图,但视图底部有一个按钮。我已经知道如何动态膨胀视图,然后膨胀其他膨胀视图下方的按钮。但是,当只有几个膨胀视图(导致组合视图占用的空间少于整个屏幕)时,按钮不会像我想要的那样位于页面底部。我的想法是,我需要通过将按钮设置为:android:layout_alignParentBottom(当我尝试执行此操作时,尽管应用程序崩溃)来使按钮在相对布局的底部对齐
这是我所拥有的屏幕截图,然后是我想要的屏幕截图,您看到的所有项目都被膨胀到相对布局内的滚动视图上。我认为问题在于按钮被充气到滚动视图上,而滚动视图的大小仅在项目强制它的情况下(不幸的是我太菜鸟不知道如何充气到视图的不同部分)
左侧图像的代码如下(我没有左侧视图的错误): 父视图:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/blurybg"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_height="wrap_content"
android:id="@+id/scrollView1"
android:layout_width="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id= "@+id/parent_of_inflated_view_id">
</LinearLayout>
</ScrollView>
</RelativeLayout>
childButton(其他视图与此类似)
<?xml version="1.0" encoding="utf-8"?>
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="30dp"
android:layout_width="fill_parent"
android:background="@drawable/done"
android:layout_alignBottom ="@layout/availablerestaurants"
/>
用于创建充气机和充气按钮的 Java。其他充气视图与此类似(我当然使用相同的充气机)。我最后添加了充气按钮以使其位于视图的底部。
LayoutInflater theInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
LinearLayout linLayout = (LinearLayout)findViewById(R.id.parent_of_inflated_view_id);
Button doneButtonCurrentRest= (Button) theInflater.inflate(R.layout.done_button_availrest, null);
linLayout.addView(doneButtonCurrentRest);
感谢您的帮助, 亚当
【问题讨论】:
-
一段代码将有助于指出您的错误。
-
另外,“android:layout_alignParentBottom”为什么失败也很不清楚。请提供一些异常日志。
-
仅供参考:当我尝试对齐父底部时,我没有膨胀按钮,我只是将按钮放在父视图 xml 中并将其设置为对齐相对布局的父底部。我想我不能在按钮和视图顶部之间膨胀我的其他视图?
标签: android xml android-layout android-xml