简体   繁体   English

带有RelativeLayout且在其中具有imageView的LinearLayout不考虑权重约束

[英]LinearLayout with RelativeLayout having imageView inside don't respect weight constraint

I don't understand how the ImageView size works on a relative layout having weight defined 我不明白ImageView大小如何在已定义权重的相对布局上工作

This is my code: 这是我的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".CameraActivity" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="76" >

        <ImageView
            android:id="@+id/imagePreview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/photo_placeholder" />

        <Button
            android:id="@+id/timeButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:onClick="onClick"
            android:text="Button" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="24" >

        <ImageButton
            android:id="@+id/mainButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:background="#0fff"
            android:src="@drawable/cam_main_btn_normal" />

        <ImageButton
            android:id="@+id/nextButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="22dp"
            android:background="#0fff"
            android:src="@drawable/gs_05_check_normal" />

        <ImageButton
            android:id="@+id/cancelButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="22dp"
            android:background="#0fff"
            android:src="@drawable/cam_cancel" />
    </RelativeLayout>

</LinearLayout>

and I get 我得到 结果错误 but if I remove the image it shows dimentions correctly as I expect 但是,如果我删除图像,它会按预期正确显示尺寸 没有imageView的结果

So the question is, how should I do to get the imageView to take the full space respecting the weight on the relative layout? 所以问题是,我该如何考虑相对布局的权重,使imageView占据全部空间?

I tried to change the android:layout_width, android:layout_height of the imageView to wrap_content (make no sense, but just' checking) it doesn't work. 我试图将imageView的android:layout_width,android:layout_height更改为wrap_content(没有意义,但只是在“检查”),它不起作用。 I tried with and without scaleType, and different values, doesn't change. 我尝试使用和不使用scaleType,并且不同的值都不会改变。

I guess ImageView needs some trick/magic? 我想ImageView需要一些技巧/魔术吗?

-- EDIT -- I'm expecting that the image will take the size highligted in blue on the second screenshoot :) -- EDIT -- What I want to achieve: -编辑-我希望图像在第二次屏幕截图时将采用蓝色高亮显示的尺寸:)-编辑-我想要实现的目标: 我想要达到的结果

In fact that code was good and it's more of an eclipse "preview" bug as it works on device (did not have a chance to test before) 实际上,代码是好的,并且它更像是蚀“预览”错误,因为它可以在设备上运行(之前没有机会进行测试)

Sorry all 不好意思

still not getting what you are trying,your way to working with weight is may be wrong. 仍然没有得到您正在尝试的东西,您的减肥方法可能是错误的。 but try this demo, hope it will help you to understand weight. 但请尝试此演示,希望它可以帮助您了解体重。

just paste it into xml. 只需将其粘贴到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:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight=".80" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@drawable/ic_launcher" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight=".20" >

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="33.33"
            android:background="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="33.33"
            android:background="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="33.33"
            android:background="@drawable/ic_launcher" />
    </LinearLayout>

</LinearLayout>

still if any query about weight,then plz ask. 如果仍然有任何关于体重的查询,那么请询问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM