gpt4 book ai didi

android - 根据屏幕设备大小调整图像按钮大小

转载 作者:行者123 更新时间:2023-11-29 16:57:38 27 4
gpt4 key购买 nike

我想根据用户的屏幕设备尺寸动态调整我的图像按钮尺寸。

我已经了解 LinearLayout 并为每个图像按钮设置权重。但是我的设计有点不同

这是我的设计: https://ibb.co/cudSCa

*这里有一个动画,中间按钮会淡入,然后其他按钮会在中间按钮中出现 *

这是xml代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/bgf"
tools:context="com.example.kixkikx.basewalk.AdminMenu">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<ImageView
android:id="@+id/imageView6"
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_marginTop="180dp"

android:layout_marginLeft="70dp"
app:srcCompat="@drawable/finalogo" />

<ImageButton
android:id="@+id/button19"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="130dp"
android:layout_marginTop="450dp"
android:onClick="Timeline"

android:background="@drawable/timeline1" />

<ImageButton
android:id="@+id/button7"
android:layout_width="60dp"

android:layout_height="60dp"
android:layout_marginLeft="140dp"
android:layout_marginTop="20dp"
android:background="@drawable/create1"
android:onClick="CreateDF" />

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="135dp"
android:layout_marginTop="80dp"

android:text="Add forum"
android:textColor="#F3D42C" />

<ImageButton
android:id="@+id/button5"

android:layout_width="50dp"
android:layout_height="60dp"
android:layout_marginLeft="253dp"
android:layout_marginTop="90dp"
android:onClick="AssignTask"
android:background="@drawable/assign1" />

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_marginTop="150dp"

android:text=" Assign Task"
android:textColor="#F3D42C" />


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST"
android:textSize="16sp"
android:textColor="#984491"
android:visibility="invisible"
android:id="@+id/textView4"
android:layout_marginBottom="30dp"
android:layout_marginRight="50dp"
android:layout_marginTop="150dp"
android:layout_marginLeft="50dp" />

<ImageButton
android:id="@+id/button8"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="90dp"
android:background="@drawable/forum1"
android:onClick="ViewManager"
android:text="Log History" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="150dp"
android:text="View Forum"
android:textColor="#F3D42C"
/>

<TextView
android:id="@+id/textView99"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120dp"
android:layout_marginTop="495dp"

android:text="View timeline"
android:textColor="#F3D42C" />

<ImageButton
android:id="@+id/button6"
android:layout_width="60dp"
android:layout_height="60dp"
android:onClick="ViewTask"
android:layout_marginLeft="30dp"
android:layout_marginTop="350dp"
android:background="@drawable/report1"
/>

<TextView
android:id="@+id/textView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="410dp"
android:layout_marginLeft="13dp"

android:textColor="#F3D42C"
android:text="View Task Reports" />


<ImageButton
android:id="@+id/button10"
android:layout_width="60dp"
android:layout_height="60dp"

android:layout_marginTop="350dp"
android:layout_marginLeft="230dp"
android:background="@drawable/logout1" />

<TextView
android:id="@+id/textView23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="410dp"
android:layout_marginLeft="240dp"

android:textColor="#F3D42C"
android:text="Log out" />

</RelativeLayout>
</RelativeLayout>

我的问题是:我不知道如何使这些图像按钮成为动态的,它会根据设备/手机的屏幕尺寸调整其大小,同时保持我创建的设计。imagebutton 中的所有图像都有 hdpi/xhdpi/xxhdpi。我使用图像 Assets 生成了这些图标。

我还想包含要为每个图像按钮对齐的 textView。

最佳答案

问题是,在这种情况下,您在宽度和高度上给出了硬代码维度,图像从 hdpi xhdpi 获取任何其他内容,但您需要在维度值文件夹值 21 中定义每个维度值,值小,值大一旦你设置我认为你可以看到最好的结果

关于android - 根据屏幕设备大小调整图像按钮大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44341363/

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