gpt4 book ai didi

android - 在布局的绝对中心显示一个矩形框

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:21:46 25 4
gpt4 key购买 nike

我想在高度为 h/3 和宽度为 3w/5 的布局中的绝对中心显示一个矩形框(w:屏幕宽度,h:屏幕高度)。请帮助我找到解决方案,在此先感谢。

最佳答案

您可以使用权重使用线性布局调整它我在下面粘贴了示例代码,希望对您有所帮助。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/transparent"
>

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="5"
/>
<TextView
android:id="@+id/desiredbox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView"
android:layout_gravity="center"
android:background="@color/skyblueBackground"
android:layout_weight="1"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="5"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>

关于android - 在布局的绝对中心显示一个矩形框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16184217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com