簡體   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