2011-12-16 92 views
0

我无法弄清为什么我的图像不在我的图像视图范围内。相反,它漂浮在左边并隐藏起来。这是因为图形界面没有显示它吗?图像越界图像视图

编辑:

我编辑的原代码,以更清楚地显示我遇到的问题,并增加了一个图(我希望图像中红色框显示):

enter image description here

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
    android:id="@+id/top_container" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"  
    android:gravity="center" 
    > 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     > 
     <View 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="195" 
      android:background="#00FF00"/> 
     <ImageView 
      android:id="@+id/img" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:background="#ff0000" 
      android:src="@drawable/img" /> 

     <View 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:background="#0000FF" 
     /> 
    </LinearLayout> 
</LinearLayout> 

回答

0

好吧我有它的工作。 “block_container”的高度属性设置为随机200dp,您可以根据自己的需要更改高度,或者将其设置为“wrap_content”。我在仿真器和设备上测试了这一点。

我还假设你想让所有三个块的间距相等。请注意父级“block_container”的weight_sum是否为9?那么这些孩子的宽度是相等的,因为他们的体重是3(每块3块* 3重量=总共9块)。

我注意到它看起来像你试图直接使用重量作为宽度例如重量为569.请直接记住重量!=宽度。

编辑:添加缺少的ID从一些我更新的问题有点意见

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/top_container" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

    <LinearLayout 
     android:id="@+id/block_container" 
     android:layout_width="fill_parent" 
     android:layout_height="200dp" 
     android:orientation="horizontal" 
     android:weightSum="9" 
     > 
     <View 
      android:id="@+id/left_block" 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="3" 
      android:background="#00FF00"/> 
     <ImageView 
      android:id="@+id/img" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="3" 
      android:background="#ff0000" 
      android:src="@drawable/logo" /> 

     <View 
      android:id="@+id/right_block" 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="3" 
      android:background="#0000FF" 
     /> 
    </LinearLayout> 
</LinearLayout> 
0

为什么你将android:layout_height设置为0dp?除非我将其更改为类似fill_parent的东西,否则我甚至无法展示它。

无论哪种方式,其因为您的layout_weight父母LinearLayout。为您的ImageView指定一个较大的layout_weight,它将会出现。

<ImageView 
     android:id="@+id/my_img" 
     android:gravity="center" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="279" 
     android:src="@drawable/my_img" /> 

这对我有效..但数学可能是不正确的。

+0

属性。也许我不理解什么?我需要增加体重吗?图像是否应该处于边界? – prostock 2011-12-17 00:09:01

+0

你甚至尝试过吗?我复制了问题并通过增加ImageView的重量来解决问题。 – styler1972 2011-12-17 02:55:29

0

我不知道从哪里开始的各种问题与你发布什么,甚至进一步调试之前的一些简单的观察:

  • 你的布局,都需要IDS(如机器人:ID =“@ + ID/another_layout“)
  • 您对0dp的第二线性布局的宽度
  • 你的第一线布局有0 DP的高度,与前组合我很惊讶它呈现在所有
  • 最后的内部线性布局的宽度为0dp

你想达到什么目的?对我来说,似乎有很多布局,除非你删除了一些元素,以便更容易理解?您可以发布您正在尝试做的事情的简单图片,或许我们可以帮助您完善标记?