我目前正在更新应用程序,我需要知道该应用程序是否在iPad中使用.
我在网上查了一下,发现下面的代码.我在Xcode中使用了iPad模拟器并运行了两个if语句.但每当我运行代码时,没有任何反应(打印消息不打印)这个代码是否适用于模拟器或我做错了什么?
当我检查它是否是UIUserInterfaceIdiom.phone时,print语句会执行,但我在模拟器中使用了iPad.
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad){
print("This is an iPad")
redoButton.layer.position.y -= 500
}
if UIDevice.current.userInterfaceIdiom == .pad{
print("iPad True")
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我开始使用 Android Studio 为 android 设备开发应用程序。当我测试我的应用程序的屏幕尺寸兼容性时,我注意到图像视图不会自动调整大小。
imageview 的位置在不同的屏幕尺寸下看起来完全不同。如果屏幕足够小,imageview 有时会被放置在 viewscope 之外。
我已经浏览了整个互联网,但我对如何使该应用程序与大多数屏幕尺寸(不包括平板电脑)兼容感到有些困惑。我去了android网站,他们说要使用wrap_content。但是如果我使用它,我将无法将图像视图的高度和宽度调整为我想要的。
有谁知道如何根据屏幕尺寸使 imageview 自动调整大小?
以下是正在发生的事情的图像:
这是应用程序的布局:
这就是我想要的样子(Pixel 3):
但这就是它在较小屏幕(Nexus 5)中的样子:
在 Xcode 中有一个称为自动调整大小的功能,可以自动为您调整内容大小。android studio 有类似的东西吗?
这是xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<Button
android:id="@+id/resetButton"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginBottom="56dp"
android:background="#F70000"
android:text="Undo"
android:textColor="#000000"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="288dp"
android:layout_height="248dp"
android:background="#1750DF"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.685" />
</androidx.constraintlayout.widget.ConstraintLayout>Run Code Online (Sandbox Code Playgroud)
先感谢您!