我正在尝试创建一个设计(我在这个-_-上非常糟糕),在这里我将有一个滚动视图和一组3个按钮,水平对齐总是在屏幕底部(我的意思是滚动视图应该在我的布局之上,我的按钮可以滚动,但是这个按钮必须总是显示/可见的)
我已经尝试过几种解决方案,最后一种我使用的是这个,但它没有成功:
<?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>
注:我不需要“头”部分.但我找到的最后一段代码似乎就是我需要的.似乎只有_
我对这个设计有两个问题(当我问的时候,我问所有的问题:p )
如何强制我将下载到ImageView1的图像大小到一个“最大”高度(我的意思是我的图片将是肖像或景观.比如说10*15和15*10 .我怎么能强迫他们10*6.666而不是15*10 <= --这就是一个例子.我不知道我会有多大的图像,但我知道每次我都希望它们在相同的高度上,宽度可能会根据比例而变化)
[2]为什么林特用红色写这部分.
android:textAppearance="?android:attr/textAppearanceLarge"提前通知每一个停在这里并给我提示的人:) (对我的英语很抱歉)
编辑:我找到了一些答案!!我用的是RELATIVELayout而不是LINEARLayout,它建议我做我想做的事.
这里是“新”模板(如果有人感兴趣的话),我仍然有问题。
<?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=的“真”是为RelativeLayout做的,问题来自于.怎么换呢?
发布于 2016-05-18 19:24:32
尝试在您的LinearLayout (封装按钮)中使用android:layout_gravity="center"或在Button元素中使用android:layout_gravity="center"。我相信第一个选择就足够了。
编辑:关于Lint警告消息,我相信它与这一行有关:android:text="Chargement en cours"
不鼓励使用硬编码字符串。尝试用android:text="@string/my_string_id"替换它,并在strings.xml文件中定义这样的字符串。
https://stackoverflow.com/questions/37307674
复制相似问题