【问题标题】:How do I extend my app main.xml so it shows my "stuff" off the bottom of the display?如何扩展我的应用程序 main.xml 以便在显示屏底部显示我的“东西”?
【发布时间】:2012-06-27 23:02:01
【问题描述】:

我在 Android 应用程序的主要活动中有很多输入框。我遇到的麻烦是我一生都找不到如何将视图(滚动)向下扩展到页面底部的框。

我尝试了滚动视图,但这只是锁定了我的应用程序。

最后一个 TextView 不显示

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >


<TextView
    android:id="@+id/textView1"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/title"
     />

<EditText

    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/action"
    android:textAppearance="?android:attr/textAppearanceLarge" />



<EditText

    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/company"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText

    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/when"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<CalendarView
    android:id="@+id/calendarView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/what_now"
    android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

【问题讨论】:

  • 这可能对您没有帮助,但您应该重新考虑您的活动方法,因为用户通常很懒惰并且不能很好地理解滚动的需要。
  • 我正在为自己制作应用程序.. 或尝试.. 我想要做的就是创建一个表单,其中包含我输入的一些信息,这些信息存储在我可以查看的数据库中.. 基本上是记录事情我每周做一次。
  • 有必要在同一个页面记录这么多东西吗?您不能将输入拆分为 2 个或更多活动并遵循类似安装程序的方法 (next-next-next-save) 方法吗?
  • 我认为布局编辑器无论如何都会显示所有项目。但是我以前的技巧是将顶部视图的可见性设置为消失,因此较低的视图会显示出来。我正在考虑您在通过布局编辑器添加视图时遇到问题。
  • 我想我可以将它们分开,但这将是一条漫长的道路,因为我更喜欢在一个页面中输入所有内容,然后在列表中的另一个活动中查看结果.. 我很可能会说话这里很垃圾,但这就是我喜欢它的方式。该应用程序基本上是我回顾的参考

标签: android android-layout layout scrollview


【解决方案1】:

Scrollview 应该可以工作。试试这个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white"
    android:orientation="vertical"
    android:scrollbars="vertical" >

    <ScrollView
        android:id="@+id/setupScroll"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/white" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:orientation="vertical"
            android:scrollbars="vertical" >

        your stuff here....

        </LinearLayout>
    </ScrollView>
</LinearLayout>

【讨论】:

  • 我认为你不需要最外层的LinearLayout
  • 也许不是,但即便如此,这仍然对我有用。我的布局与提问者的几乎一模一样。
  • 很公平。请记住,每次嵌套元素时都会消耗内存。
  • 啊,是的。 @jamie,请注意这一点。或许 Aleks 的回答最好先尝试一下。
  • 啊,滚动视图有效.. 除了最后一个 中的小 v 哈哈.. 让我有点困惑.. 谢谢大家..
【解决方案2】:

您需要将您的 LinearLayout 放入 ScrollView:

<ScrollView android:id="@+id/scroll" xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

    <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/title"
             />

        <EditText

            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/action"
            android:textAppearance="?android:attr/textAppearanceLarge" />



        <EditText

            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/company"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText

            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/when"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <CalendarView
            android:id="@+id/calendarView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/what_now"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>
</ScrollView>

【讨论】:

    猜你喜欢
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    相关资源
    最近更新 更多