【发布时间】:2021-08-05 10:00:32
【问题描述】:
所以我一直在构建一个简单的登录屏幕,设备的显示尺寸正在影响布局,并且在不同的设备上不断变化,android studio 的新手有解决方案吗?
XML 代码
它是一个带有 Neumorphism 的简单布局。
**而且我知道我们可以使布局响应约束,但是除了约束布局之外还有其他方法吗? **
<ScrollView 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:orientation="vertical"
tools:context=".Admin.AdminStuff.SettingUp.admin_log_in">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/backButton_students"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/arrow_back"
app:tint="@color/black" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:fontFamily="@font/muli"
android:text="SUMS"
android:textColor="@color/appcolor"
android:textSize="60sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="2dp"
android:fontFamily="sans-serif-medium"
android:text="Log In"
android:textColor="@color/black"
android:textSize="28sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="20dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="-4dp"
android:layout_marginTop="50dp"
android:layout_marginBottom="-5dp"
android:text="Please select the Institution & Class"
android:textAlignment="center"
android:textColor="@color/darkblue"
android:textSize="18sp"
android:textStyle="bold" />
<Spinner
android:id="@+id/spinner_students_login"
style="@style/Widget.AppCompat.DropDownItem.Spinner"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginStart="30dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="30dp"
android:background="#f5f7fa"
android:textAlignment="center" />
<Spinner
android:id="@+id/spinner_programmes_students_login"
style="@style/Widget.AppCompat.DropDownItem.Spinner"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginStart="30dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="30dp"
android:background="#f5f7fa"
android:textAlignment="center" />
<soup.neumorphism.NeumorphCardView
style="@style/Widget.Neumorph.CardView"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginStart="15dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="5dp"
app:neumorph_shapeType="pressed">
<EditText
android:id="@+id/registrationNumber_studentslogin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/no_background"
android:hint="Email Id"
android:inputType="textEmailAddress"
android:paddingStart="15dp"
android:textCursorDrawable="@drawable/cursor" />
</soup.neumorphism.NeumorphCardView>
<soup.neumorphism.NeumorphCardView
style="@style/Widget.Neumorph.CardView"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
app:neumorph_shapeType="pressed">
<EditText
android:id="@+id/password_studentslogin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/no_background"
android:hint="Password"
android:inputType="textVisiblePassword"
android:maxLines="1"
android:paddingStart="15dp"
android:textCursorDrawable="@drawable/cursor" />
</soup.neumorphism.NeumorphCardView>
</LinearLayout>
<soup.neumorphism.NeumorphButton
android:id="@+id/forgotpassword_students"
style="@style/Widget.Neumorph.Button"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="right"
android:layout_marginLeft="8dp"
android:layout_marginTop="-25dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:backgroundTint="@color/white"
android:text="Forgot Password?"
android:textColor="#636363"
android:textStyle="bold"
app:neumorph_lightSource="leftTop"
app:neumorph_shadowColorDark="@color/white" />
<CheckBox
android:id="@+id/remeberme_student"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/login_teachers"
android:layout_marginStart="25dp"
android:layout_marginTop="-60dp"
android:layout_marginBottom="25dp"
android:text="Remember Me"
android:textColor="@color/black"
android:textSize="16sp" />
<soup.neumorphism.NeumorphButton
android:id="@+id/login_students"
style="@style/Widget.Neumorph.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginTop="25dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="10dp"
android:backgroundTint="@color/appcolor"
android:text="Log In"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold"
app:cornerRadius="4dp"
app:neumorph_backgroundColor="@color/appcolor" />
<ProgressBar
android:id="@+id/progressbar_students"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:outlineSpotShadowColor="@color/white" />
<soup.neumorphism.NeumorphButton
android:id="@+id/adminNewUser_student"
style="@style/Widget.Neumorph.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="-15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="10dp"
android:backgroundTint="@color/white"
android:shadowDx="-2"
android:shadowDy="-2"
android:shadowRadius="1"
android:text="New User? Sign Up"
android:textColor="@color/darkblue"
android:textSize="18sp"
android:textStyle="bold"
app:cornerRadius="4dp" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="80dp"
android:src="@drawable/bottom" />
</LinearLayout>
【问题讨论】:
-
is there a solution ?当然。利用较小的尺寸,使用约束布局之类的东西,练习更多的布局。如果您不提供代码,则无法解决 -
是的,约束布局使屏幕响应。但除此之外还有其他方法吗,因为约束布局太痛苦了。
标签: android xml android-layout layout