如何使ImageView浮动在LinearLayout上方?

阿里特拉(Aritra Bhattacharyya)

请检查以下图片的链接。由于声誉低下,我无法发布图片。

http://i.stack.imgur.com/nupZo.png

我的目标是要获得一种类似于左图的布局,而不是获得一种如右图的布局。这是我的布局的xml代码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@color/metalDark"
android:orientation="vertical"
>
<LinearLayout
    android:id="@+id/topPanel"
    android:layout_width="fill_parent"
    android:layout_height="65dp"
    android:background="@color/metalList"
    android:elevation="6dp"
    android:layout_marginBottom="5dp"
    android:orientation="horizontal">

    <TextView
        .../>


</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/topPanel"
    android:layout_margin="10dp"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/albumheader"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:background="@color/metalList"
        android:elevation="6dp">
        <LinearLayout
            android:id="@+id/underlay"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="25dp"
            android:layout_marginBottom="25dp"
            android:background="@drawable/canvas2">
        <ImageView
            android:id="@+id/al_art"
            android:layout_width="135dp"
            android:layout_height="135dp"
            android:layout_toLeftOf="@+id/al_details"
            android:layout_marginLeft="25dp"
            android:layout_marginTop="-17dp"
            android:elevation="4dp"/>
        <LinearLayout
            android:id="@+id/al_details"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="right|center"
            android:orientation="vertical">

            <TextView
                .../>
            <TextView
                .../>
            <TextView
                .../>

        </LinearLayout>
            </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:background="@color/metalList"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="15dp"
        android:elevation="6dp"
        >
        <ListView
            ..../>
    </LinearLayout>

</LinearLayout>

夏洛克

LinearLayoutViews彼此叠加并不是很好

本文对于获取更多信息非常有帮助:http : //android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

这是我会做的:

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

    <View
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_marginBottom="12dp"
        android:layout_height="?listPreferredItemHeight"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_marginStart="12dp"
        android:layout_marginEnd="12dp"
        android:layout_marginBottom="12dp"
        android:layout_height="wrap_content">


        <ImageView
            android:id="@+id/img_orange_rectangle"
            android:background="#ff6600"
            android:layout_centerVertical="true"
            android:layout_width="match_parent"
            android:layout_height="128dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_centerVertical="true"
            android:text="hi I'm some text"
            android:gravity="end|top"
            android:padding="6dp"
            android:layout_alignStart="@id/img_orange_rectangle"
            android:layout_alignEnd="@id/img_orange_rectangle"
            android:layout_alignBottom="@id/img_orange_rectangle"
            android:layout_alignTop="@id/img_orange_rectangle"
            android:layout_height="0dp"/>


        <ImageView
            android:id="@+id/img_blue_square"
            android:background="#2541ba"
            android:layout_marginStart="24dp"
            android:layout_centerVertical="true"
            android:layout_width="156dp"
            android:layout_height="156dp"/>
    </RelativeLayout>


    <ListView
        android:id="@+id/listview"
        android:layout_marginStart="12dp"
        android:layout_marginEnd="12dp"
        android:layout_marginBottom="12dp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>
</LinearLayout>

根据以下评论,于20158月15日更新

但是,请告诉我为什么将RelativeLayout的layout_height保持为0?

我在上使用了0的高度,RelativeLayout因为布局基于来获取其高度layout_weight

橙色矩形的高度会根据设备和屏幕尺寸而变化吗?

不会。尽管我已经更新了布局以能够这样做。我推荐这篇文章,以了解如何支持多种屏幕尺寸。此StackOverflow第2部分的底部,它讨论了Google IO pdf中每个屏幕尺寸的xml尺寸。

另外,如果我想将文本放入橙色矩形内,如何确保将其保留在橙色矩形内?

我在上面添加了另一种布局。有多种解决方法。我选择的是使它TextViewImageView上面的属性对齐

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何使浮动图片浮动到div的右上方?

来自分类Dev

如何添加一个浮动在UIScrollView上方的按钮?

来自分类Dev

如何动态显示浮动文本区域的上方或下方?

来自分类Dev

如何将警报浮动到导航栏上方?

来自分类Dev

如何在浮动操作按钮上方放置透明布局

来自分类Dev

如何让文本字段在mapView上方悬停/浮动

来自分类Dev

如何用%将ImageView放置在LinearLayout的顶部?

来自分类Dev

菜单上方的浮动搜索栏

来自分类Dev

固定元素上方的浮动元素

来自分类Dev

如何在RelativeLayout中的LinearLayout上获取ImageView

来自分类Dev

在Ionic 2中,当键盘显示时,如何在键盘上方浮动元素?

来自分类Dev

如何阻止标题和下部文本在左上方浮动的img元素周围流动

来自分类Dev

如何使内容浮动在页面上方/弹出窗口不起作用

来自分类Dev

ImageView比LinearLayout背景的优势

来自分类Dev

LinearLayout 上的 Android Imageview

来自分类Dev

Android LinearLayout 重叠 imageView

来自分类Dev

波纹效果不在ImageView上方

来自分类Dev

在剑道图表栏上方排列浮动div

来自分类Dev

容器块元素上方的浮动汉堡菜单

来自分类Dev

ListView Flutter上方的浮动操作按钮

来自分类Dev

浮动右上方的顶部水平对齐

来自分类Dev

窗口内容上方的浮动通知栏

来自分类Dev

容器块元素上方的浮动汉堡菜单

来自分类Dev

绝对位置图像上方的浮动文本

来自分类Dev

列表视图上方的浮动操作按钮

来自分类Dev

在Android的ActionBar上浮动ImageView?

来自分类Dev

如何从中心而不是左上方缩放javaFX的图像(ImageView)

来自分类Dev

Android - 如何在 ImageView 的右上方添加通知计数器

来自分类Dev

如何在Android中非常长的列表视图上方为浮动操作按钮设置固定位置?

Related 相关文章

  1. 1

    如何使浮动图片浮动到div的右上方?

  2. 2

    如何添加一个浮动在UIScrollView上方的按钮?

  3. 3

    如何动态显示浮动文本区域的上方或下方?

  4. 4

    如何将警报浮动到导航栏上方?

  5. 5

    如何在浮动操作按钮上方放置透明布局

  6. 6

    如何让文本字段在mapView上方悬停/浮动

  7. 7

    如何用%将ImageView放置在LinearLayout的顶部?

  8. 8

    菜单上方的浮动搜索栏

  9. 9

    固定元素上方的浮动元素

  10. 10

    如何在RelativeLayout中的LinearLayout上获取ImageView

  11. 11

    在Ionic 2中,当键盘显示时,如何在键盘上方浮动元素?

  12. 12

    如何阻止标题和下部文本在左上方浮动的img元素周围流动

  13. 13

    如何使内容浮动在页面上方/弹出窗口不起作用

  14. 14

    ImageView比LinearLayout背景的优势

  15. 15

    LinearLayout 上的 Android Imageview

  16. 16

    Android LinearLayout 重叠 imageView

  17. 17

    波纹效果不在ImageView上方

  18. 18

    在剑道图表栏上方排列浮动div

  19. 19

    容器块元素上方的浮动汉堡菜单

  20. 20

    ListView Flutter上方的浮动操作按钮

  21. 21

    浮动右上方的顶部水平对齐

  22. 22

    窗口内容上方的浮动通知栏

  23. 23

    容器块元素上方的浮动汉堡菜单

  24. 24

    绝对位置图像上方的浮动文本

  25. 25

    列表视图上方的浮动操作按钮

  26. 26

    在Android的ActionBar上浮动ImageView?

  27. 27

    如何从中心而不是左上方缩放javaFX的图像(ImageView)

  28. 28

    Android - 如何在 ImageView 的右上方添加通知计数器

  29. 29

    如何在Android中非常长的列表视图上方为浮动操作按钮设置固定位置?

热门标签

归档