Android 布局对齐不工作
我是android studio的新手,之前使用过Android 布局对齐不工作,android,android-layout,android-styles,Android,Android Layout,Android Styles,我是android studio的新手,之前使用过layout\u alignParentBottom=“true”和其他对齐命令,效果很好。 我甚至收到了android studio在识别命令时给出的推荐意见 但现在我创建了一个新项目,Android_studio在这里提供了代码 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:androi
layout\u alignParentBottom=“true”
和其他对齐命令,效果很好。
我甚至收到了android studio在识别命令时给出的推荐意见
但现在我创建了一个新项目,Android_studio在这里提供了代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="com.example.shaurya.courtcounter.MainActivity">
<LinearLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:background="#ffdab9"
android:orientation="vertical"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:text="Team A"
android:textAppearance="?android:textAppearanceLarge" />
<TextView
android:id="@+id/team_a_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="0"
android:textAppearance="?android:textAppearanceMedium" />
<Button
android:id="@+id/threepoints"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="increment_three"
android:text="3 Points" />
<Button
android:id="@+id/twopoints"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="increment_two"
android:text="2 Points" />
<Button
android:id="@+id/onepoints"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="increment_one"
android:text="Free Throw" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="reset" />
</LinearLayout>
对齐您使用的属性:
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
不属于线性布局行为,它属于相对性
所以,如果您需要使用linearLayout(线性布局)到达重置按钮的中心,请使用
android:layout_gravity=“center | anygravityYouWant”
android:gravity=“center”
此外,由于将ConstraintLayout用作父布局,因此您在linearLayout的宽度和高度方面也面临一些问题。对齐您使用的属性:
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
不属于线性布局行为,它属于相对性
所以,如果您需要使用linearLayout(线性布局)到达重置按钮的中心,请使用
android:layout_gravity=“center | anygravityYouWant”
android:gravity=“center”
此外,由于使用ConstraintLayout作为父布局,您在linearLayout的宽度和高度方面也面临一些问题。只需使用相对布局作为父布局即可-
只需将相对布局用作父布局即可-
还有一件事,如果有人能帮上忙的话,我将以match\u家长的身份给出身高和体重的线性布局,但它会自动给标签一些固定值。为什么我不能给match_parent to LinearLayout另一件事,如果有人能在代码中提供帮助,我给LinearLayout身高和体重作为match_parent,但它自动给了该标记一些固定值。为什么我不能将match_parent指定给linearlayout或linearlayout高度和重量?请看一下,那么约束布局的解决方案是什么?我应该添加什么,以便获得全屏背景和textviews@shauryauppal如果您还不熟悉,请查看。对于线性布局,身高和体重可以请看一看,约束布局的解决方案是什么?我应该添加什么,以便获得全屏背景和textviews@shauryauppal如果您还不熟悉,请查看。“xmlns:app=”“xmlns:tools=”“android:layout\u width=“match\u parent”android:layout\u height=“match\u parent”tools:context=”com.example.shaurya.courtcounter.main活动“>您能解释一下这一默认行为什么是CONSTRAINT layout CONSTRAINT layout应该起作用吗?如果正确应用了约束,默认情况下,新的XML布局文件是以CONSTRAINT layout作为父布局定义的。将
替换为
@shauryauppal ConstraintLayout是默认值。自从Android Studio 2.3。。。您可以随意完全替换为任何您想要的布局。“xmlns:app=”“xmlns:tools=”“android:layout\u width=“match\u parent”android:layout\u height=“match\u parent”tools:context=“com.example.shaurya.courtcounter.MainActivity“>您能解释一下这一默认行为什么是CONSTRAINT layout CONSTRAINT layout应该起作用吗?如果正确应用了约束,默认情况下,新的XML布局文件是以CONSTRAINT layout作为父布局定义的。将
替换为
@shauryauppal ConstraintLayout是默认值。自从Android Studio 2.3。。。您可以自由地完全替换为您想要的任何布局。