Android 设计:下方的 scrollview 3 按钮

Android design : a scrollview 3 button below

我正在尝试创建一个设计(我在这方面很糟糕 -__- ),我将有一个滚动视图和一组 3 个按钮,它们始终水平对齐在屏幕底部(我的意思是滚动视图应该在我的按钮布局之上并且可以滚动,但按钮必须始终是 displayed/visible)

我已经尝试了好几种解决方案,我最后用的是这个,但是没有成功:(

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
    android:id="@+id/header"
    android:layout_alignParentTop="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</RelativeLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scroll"
    android:layout_above="@+id/footer"
    android:layout_below="@+id/header">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/imageView1"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Chargement en cours"
            android:id="@+id/TNom"
            android:layout_below="@+id/imageView1"
            android:layout_centerHorizontal="true" />
    </RelativeLayout>
</ScrollView>
<RelativeLayout
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    android:layout_alignParentBottom="true">

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="+"
    android:id="@+id/Bplus"
    android:onClick="onClickSuivant"
    android:layout_toLeftOf="@+id/Begale"
    android:layout_toStartOf="@+id/Begale" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="="
    android:id="@+id/Begale"
    android:onClick="onClickSuivant"
    android:layout_centerHorizontal="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="-"
    android:id="@+id/Bmoins"
    android:onClick="onClickSuivant"
    android:layout_toRightOf="@+id/Begale"
    android:layout_toEndOf="@+id/Begale" />
</RelativeLayout>

注意:我不需要 "header" 部分……但我找到的最后一个代码有它,它似乎正是我需要的……似乎只有 -__-: (

我有 2 个关于这个设计的问题(当我问的时候,我什么都问了 :p )

1/ 我如何强制将要下载到 ImageView1 中的图像的大小设置为 "maximum" 高度(我的意思是我的图片将是纵向或横向...比如说 10*15 和 15 *10 ...我怎么能强迫他们成为 10*6.666 而不是 15*10 <= 这是一个例子...我不知道我将拥有的图像尺寸,但我知道我希望它们处于相同的高度每次,宽度可能会根据比例变化)

2/为什么 Lint 将这部分写成红色....

android:textAppearance="?android:attr/textAppearanceLarge"

提前感谢所有停在这里并给我提示的人:) (对不起我的英语)

编辑:我找到了一些答案!!我用的是RELATIVELayout而不是LINEARLayout,推荐做我想做的...

Si这里是"new"模板(有兴趣的可以参考一下),我这里还有问题

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:orientation="vertical">
<ScrollView
    android:layout_width="match_parent"
    android:id="@+id/scroll"
    android:layout_height="0dp"
    android:layout_weight="1">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/imageView1"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Chargement en cours"
            android:id="@+id/TNom"
            android:layout_below="@+id/imageView1"
            android:layout_centerHorizontal="true" />
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="+"
        android:id="@+id/Bplus"
        android:onClick="onClickSuivant"
        android:layout_toLeftOf="@+id/Begale"
        android:layout_toStartOf="@+id/Begale" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="="
        android:id="@+id/Begale"
        android:onClick="onClickSuivant"
        android:layout_centerHorizontal="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="-"
        android:id="@+id/Bmoins"
        android:onClick="onClickSuivant"
        android:layout_toRightOf="@+id/Begale"
        android:layout_toEndOf="@+id/Begale" />
</LinearLayout>

在之前的设计中,按钮对齐得很好并占据了整个屏幕(match_parent)...在这个设计中,它们位于左下角...如android:layout_centerHorizontal= "true" 是为 RelativeLayout 制作的,问题出在这...我该如何更改它?

尝试在 LinearLayout(封装按钮)中使用 android:gravity="center" 或在 Button 元素中使用 android:layout_gravity="center"。我相信第一个选项就足够了。

编辑:关于 Lint 警告信息,我相信它与这一行有关: android:text="Chargement en cours"

不鼓励使用硬编码字符串。尝试用 android:text="@string/my_string_id" 替换它并在 strings.xml 文件中定义这样的字符串。