【问题标题】:postion one Imageview below another - android将一个图像视图放置在另一个图像视图下方 - android
【发布时间】:2014-01-24 03:41:15
【问题描述】:

我现在无法将一个 imageview 定位在另一个 imageview 下方。尽管我使用过 android:layout_below 似乎没有发生任何事情。我以前成功地做到了这一点。我现在唯一能想到的是这个 imageview 拥有并且图像相当大(宽度 500sp,高度 750sp)。

三个imageview的id如下-两个小view

1) 单人 2) 体积 3) extraImage(这是保存大图像的视图)

我想把 extraImage 放在单个下面

这里是xml语法

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="5dp"
  android:paddingLeft="0px"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="0px"
  android:background="#ffffff"
  tools:context=".PhraseActivity" >

   <ImageView
    android:id="@+id/single"
    android:layout_width="68sp"
    android:layout_height="68sp"
    android:layout_centerVertical="true"
    />



  <ImageView
    android:id="@+id/extraImage"
    android:layout_width="500sp"
    android:layout_height="750sp"
    android:layout_below="@+id/single"
   />


    <ImageView
    android:id="@+id/volume"
    android:layout_width="50sp"
    android:layout_height="40sp"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
   />
</RelativeLaoyout>

这就是我想要的方式

现在是这样的

所以我的问题是:我该如何解决这个问题 - 我如何将大图像视图定位在小图像视图下方(单个)?

我也尝试过 android:layout_toEndOf="" 没有成功

【问题讨论】:

  • 你在使用相对布局吗??
  • @mohammedmomn 是的 - 所有的孩子都被包裹在一个相对布局中
  • 请出示您的整个 xml 文件
  • @Aamirkhan - 我已经更新了我的代码 - 现在你可以看到完整版了

标签: android android-layout android-imageview


【解决方案1】:

看我试试这个,它给了我你需要做的想法

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

<ImageView
    android:id="@+id/img"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:contentDescription="@string/app_name"
    android:scaleType="centerCrop"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/img"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:contentDescription="@string/app_name"
    android:scaleType="centerCrop"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/img"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_below="@+id/img"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="34dp"
    android:contentDescription="@string/app_name"
    android:scaleType="centerCrop"
    android:src="@drawable/ic_launcher" />

 </RelativeLayout>

【讨论】:

    【解决方案2】:

    尝试将 ImageView1 和 ImageView2 放在水平 LinearLayout 中,然后它应该可以工作。

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    
        <ImageView
            android:id="@+id/single"
            android:layout_width="68sp"
            android:layout_height="68sp" />
    
        <ImageView
            android:id="@+id/volume"
            android:layout_width="50sp"
            android:layout_height="40sp" />
    
    </LinearLayout>
    
    <ImageView
        android:id="@+id/extraImage"
        android:layout_width="500sp"
        android:layout_height="750sp" />
    

    【讨论】:

    • 我试过了,但是编译错误,布局不是同一个兄弟。外部布局是relativeLayout,内部(你建议的)linearLayout
    • 没错,它不适用于作为父级的 RelativeLayout。你能用 LinearLayout 替换你的 RelativeLayout 吗?
    【解决方案3】:

    不要硬编码宽度和高度的值。对于前 2 个图像,使用相同的权重 Like:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    
    <LinearLayout
        android:id="@+id/linear"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    
        <ImageView
            android:id="@+id/single"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    
        <ImageView
            android:id="@+id/volume"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>
    
    <ImageView
        android:id="@+id/extraImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/linear" />
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多