繁体   English   中英

如何使用大背景图片缩小LinearLayout的尺寸

[英]How to reduce size of LinearLayout with Background Image large one

我试图垂直绘制2个布局,其中顶部包含图像,因为图像很大,它占据了botton一半的一部分,我使用权重= 1和layoutheight = 0dp对其进行平均划分,

没有任何图像,分区是完美的,但是如果我将背景图像设置为播放,则重量比不是完美的,这是无法重用的,

我尝试使用framelayout,这也没有用,

什么是在xml中执行此操作的确切方法,而不是通过编程来辅助布局高度。

尝试这个:

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

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5">
   </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5">
    </LinearLayout>
</LinearLayout>

然后,您可以将图像设置为顶部布局的背景。

如果您想给视图提供相对的空间,这里是您可以尝试使用的新的android库。

百分比支持库

https://developer.android.com/tools/support-library/features.html#percent

您可以在项目中使用它,例如:

<android.support.percent.PercentFrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_heightPercent="50%"
            app:layout_widthPercent="100%" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_gravity="bottom"
            app:layout_heightPercent="50%"
            app:layout_widthPercent="100%" />

    </android.support.percent.PercentFrameLayout>

暂无
暂无

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

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