簡體   English   中英

如何在子級縮放時調整父級布局的大小?

[英]How can I resize a parent layout when its children scale?

我有一個Horizo​​ntalScrollView包含一個水平LinearLayout,其中包含一系列自定義視圖(ToolbarButton):

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ToolbarButton/>
        <ToolbarButton/>
        ...

    </LinearLayout>

</HorizontalScrollView>

現在,在運行時,我想使用setScaleX和setScaleY將ToolbarButtons縮小。 縮放工作,但ToolbarButtons的位置不會改變,LinearLayout的大小也不會改變。

當我在xml(而不是運行時)的ToolbarButtons中使用scaleX和scaleY時,我得到相同的結果。

我的目標是動態縮小ToolbarButtons並使它們周圍的空間也縮小。 我該怎么做呢? 謝謝。

你需要告訴父母重繪自己:

if (getParent() instanceof View)
    ((View) getParent()).invalidate();

看到這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM