Tha*_*hem 9 user-interface android android-layout
我很难在Android应用中获得我想要的GUI布局结果.
我想要的简要说明:
GUI包括两个TextView和四个按钮.
四个按钮应水平布置,全部在同一行,并固定在屏幕的右下角.
两个TextView中的第一个是从屏幕顶部开始,文本内容从一行到几十行不等 - 超过屏幕适合而不滚动.因此,有时需要滚动来查看所有内容.即使需要滚动,按钮也不参与滚动:它们始终保持固定在屏幕右下角的单行中.当需要滚动时,滚动文本始终位于按钮上方 - 按钮不会覆盖文本.
两个TextView中的第二个显示在第一个TextView的正下方,通常只会在文本的总长度上添加一行或两行.当需要滚动时,第二个TextView将使用第一个TextView滚动,始终显示在第一个TextView的正下方.
其他限制包括我希望所有以下Android设备的布局看起来都不错,包括垂直和水平屏幕布局:
我会在另一天担心平板电脑(比如明天).
-
我已经尝试了许多不同的布局组合,但还没有任何一个非常接近目标.
(对于我尝试过的一些布局组合,我可以用RelativeLayout修复屏幕左下方的按钮,但是我用scolling文本尝试的所有内容都会导致文本在按钮后滚动 - 按钮覆盖文本.我还没想出让按钮与右下方对齐.)
如果有人帮助我解决这个问题,下面的布局示例xml是一个会话起点,但它肯定无法实现目标结果,如下面的屏幕截图所示,使用相同的布局示例xml生成.(虽然有些屏幕截图显示了同样的问题,但它们有助于显示我在不同屏幕上的位置.)
<?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="wrap_content">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text View 1. Text varies from a few lines to many more lines than what fits on the screen. Scrolling is necessary to see it all." />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text View 2. Short text entry sits below Text View 1." />
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button_1"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="Button 1" />
<Button
android:id="@+id/button_2"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="Button 2" />
<Button
android:id="@+id/button_3"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="Button 3" />
<Button
android:id="@+id/button_4"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="Button 4" />
</LinearLayout>
</LinearLayout>Run Code Online (Sandbox Code Playgroud)
1.5_API3_HVGA_Horizontal_MDPI - short_text:

问题:按钮应与屏幕的右下角对齐.
-
1.5_API3_HVGA_Vertical_MDPI - short_text:

问题:按钮应与屏幕的右下角对齐.
-
1.5_API3_QVGA_240x320_MDPI - short_text:

问题:第四个按钮被粉碎.首选三个按钮上的文字以便在必要时包裹,留出足够的空间来显示第四个按钮.
-
1.5_API3_QVGA_320x240_MDPI - short_text:

问题:按钮应与屏幕的右下角对齐.
-
1.6_API4_QVGA_Horizontal_LDPI - long_text:

问题:当文本几乎填满屏幕时,按钮行被粉碎.按钮行不应该被粉碎,应该固定在屏幕的右下角.文本应滚动到按钮上方.
-
1.6_API4_QVGA_Horizontal_LDPI - short_text:

问题:按钮应与屏幕的右下角对齐.
-
1.6_API4_QVGA_Horizontal_LDPI - very_long_text,顶部滚动条:

问题:按钮不在屏幕上.它们应固定在屏幕的右下角.
-
1.6_API4_QVGA_Horizontal_LDPI - very_long_text,底部的滚动条:

问题:虽然文本滚动条位于底部,但按钮无处可寻.它们应固定在屏幕的右下角.
-
1.6_API4_QVGA_Vertical_LDPI - short_text:

问题:按钮应与屏幕的右下角对齐.
-
有什么建议?
-
附加信息:当我尝试使用RelativeLayout,并修复屏幕底部的按钮时android:layout_alignParentBottom="true",我的问题是我不知道如何用按钮顶部修复滚动视图的底部.使用android:layout_alignBottom="@id/buttons"刚刚将滚动视图的底部与按钮的底部对齐,然后按钮覆盖文本,如下所示:
-
更新:解决了将按钮固定到右下方的问题,以及按钮上方的滚动文本.
这是目前为止工作的更改的布局XML(如果要查看滚动,请将更多文本粘贴到文本视图1中):
<?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:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text View 1. Text varies from a few lines to many more lines than what fits on the screen. Scrolling is necessary to see it all." />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text View 2. Short text entry sits below Text View 1." />
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right">
<Button
android:id="@+id/button_1"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="Button 1" />
<Button
android:id="@+id/button_2"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="Button 2" />
<Button
android:id="@+id/button_3"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="Button 3" />
<Button
android:id="@+id/button_4"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="Button 4" />
</LinearLayout>
</LinearLayout>Run Code Online (Sandbox Code Playgroud)我还有一个问题,我将发布一个新问题.
| 归档时间: |
|
| 查看次数: |
9260 次 |
| 最近记录: |