android-linearlayout 相关问题

LinearLayout是Android中的基本布局之一。它可以水平或垂直地将孩子一个接一个地安排好。

我如何以编程方式在线性布局中添加TextView?

我有一个用Kotlin开发的应用程序,该应用程序使用线性布局,我想在其中插入多个TextView。由于TextView的数量可以更改,因此我想在代码中动态添加它们,而不是...

回答 1 投票 0

我如何以编程方式在线性布局中添加TextView?

我有一个用Kotlin开发的应用程序,该应用程序使用线性布局,我想在其中插入多个TextView。由于TextView的数量可以更改,因此我想在代码中动态添加它们,而不是...

回答 1 投票 0

Layout和drawable的居中方式不同

我的初始屏幕有两种布局,它们基本上由一个位于屏幕中心的图标组成。其中之一是drawable / launch_screen.xml。这个用于AppTheme。

回答 1 投票 0

视图被打包在ConstraintLayout中,视图在LinearLayout中用尽屏幕

我正在像下面那样实现一个注册/登录屏幕,我已经像下面这样使用ConstraintLayout来尝试了这个 [ 我建议您使用所有的屏幕密度,而不要使用所有的密度,您可以使用著名的库SDP或遵循android提供的指南。第二次使用Constraintlayout的Guideline类。这是示例代码片段,您也可以使用此代码片段。 <?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" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="16dp"> <ImageView android:id="@+id/img" android:layout_width="@dimen/_200sdp" android:layout_height="@dimen/_200sdp" android:layout_marginTop="16dp" android:src="@drawable/ic_launcher" app:layout_constraintBottom_toTopOf="@+id/btn1" app:layout_constraintEnd_toStartOf="@+id/right" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="@+id/left" app:layout_constraintTop_toTopOf="parent" /> <Button android:id="@+id/btn1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="Button 1" app:layout_constraintBottom_toTopOf="@+id/btn2" app:layout_constraintEnd_toStartOf="@+id/right" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="@+id/left" app:layout_constraintTop_toBottomOf="@+id/img" /> <Button android:id="@+id/btn2" android:layout_width="0dp" android:layout_height="wrap_content" android:text="Button 2" app:layout_constraintBottom_toTopOf="@+id/txt_already_member" app:layout_constraintEnd_toStartOf="@+id/right" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="@+id/left" app:layout_constraintTop_toBottomOf="@+id/btn1" /> <TextView android:id="@+id/txt_already_member" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="Already Member? Sign In" android:textSize="16sp" app:layout_constraintBottom_toTopOf="@+id/divider" app:layout_constraintEnd_toStartOf="@+id/right" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="@+id/left" app:layout_constraintTop_toBottomOf="@+id/btn2" /> <TextView android:id="@+id/txt_agreement" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="24dp" android:text="By continuing you agree to our terms and privacy policy" android:textSize="12sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/right" app:layout_constraintStart_toStartOf="@+id/left" app:layout_constraintTop_toTopOf="@+id/divider" app:layout_constraintVertical_bias="1.0" /> <androidx.constraintlayout.widget.Guideline android:id="@+id/left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" app:layout_constraintGuide_begin="@dimen/_16sdp" /> <androidx.constraintlayout.widget.Guideline android:id="@+id/right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" app:layout_constraintGuide_end="@dimen/_16sdp" /> <androidx.constraintlayout.widget.Guideline android:id="@+id/divider" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintGuide_percent="0.7" app:layout_constraintTop_toBottomOf="@+id/txt_already_member" /> 实际上,我的问题的解决方案是将Guideline中的ConstraintLayout与Guideline的app:layout_constraintGuide_percent属性一起使用,并将视图限制为准则。 由于app:layout_constraintGuide_percent的值是 percentage 而不是dp值,所以不管屏幕的宽度/高度如何,它都响应良好。 示例: <?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" android:layout_margin="16dp" tools:context=".MainActivity"> <ImageView android:id="@+id/img" android:layout_width="250dp" android:layout_height="200dp" android:src="@drawable/ic_launcher_background" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/guideline4" /> <Button android:id="@+id/btn1" android:layout_width="match_parent" android:layout_height="56dp" android:layout_marginStart="20dp" android:layout_marginEnd="20dp" android:text="Button 1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="1.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/guideline5" /> <Button android:id="@+id/btn2" android:layout_width="match_parent" android:layout_height="56dp" android:layout_marginTop="8dp" android:layout_marginStart="20dp" android:layout_marginEnd="20dp" android:text="Button 2" app:layout_constraintEnd_toEndOf="@+id/btn1" app:layout_constraintStart_toStartOf="@+id/btn1" app:layout_constraintTop_toBottomOf="@+id/btn1" /> <TextView android:id="@+id/txt_already_member" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:layout_marginBottom="16dp" android:text="Already Member? Sign In" android:textSize="16sp" app:layout_constraintBottom_toTopOf="@+id/txt_agreement" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/btn2" /> <TextView android:id="@+id/txt_agreement" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="32dp" android:text="By continuing you agree to our terms and privacy policy " android:textSize="12sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> <androidx.constraintlayout.widget.Guideline android:id="@+id/guideline4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_percent=".1" /> <androidx.constraintlayout.widget.Guideline android:id="@+id/guideline5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_percent=".6" /> </androidx.constraintlayout.widget.ConstraintLayout> 非常感谢Rehan Sarwar记得我关于Guideline的内容。

回答 2 投票 0

以编程方式管理LinearLayout

我有一个正在以编程方式构建的类,我需要调整2按钮的布局以使其看起来与其他类相似。在此类AttributeWizard中,我正在遍历代码,因为我正在执行...

回答 1 投票 0

[在android中单击线性布局时将选择单选按钮

我创建了一个包含2个线性布局的1个单选组。这2个线性布局分别包含1个单选按钮。创建线性布局仅是为了将样式应用于收音机组和...

回答 1 投票 1

为什么片段中的EditText导航到另一个片段并在Kotlin中使用后退按钮返回相同的值?

我是Android开发和Kotlin的新手。我碰到了这个使我感到困惑的问题。我在片段A中有2个EditText元素,每个元素都有不同的文本。当我导航到片段B和...

回答 2 投票 0

在右上角放置标签

我正在尝试在卡片视图右侧的版式中放置一个“新”标签:Android Studio中没有任何预览:虽然版式已显示,但内容可能未显示...] >

回答 1 投票 0

Android Cardview:在右上角放置标签

我正在尝试在卡片视图右侧的版式中放置一个“新”标签:Android Studio中没有任何预览:虽然版式已显示,但内容可能未显示...] >

回答 1 投票 0

如果线性布局的重力=“底部”时滚动不起作用,该怎么办?

我通过将消息元素动态添加到linearlayout来显示聊天。我遇到了一个问题。合乎逻辑的是,进入时,抬起键盘滚动条不应落在下面,并且...

回答 1 投票 0

LinearLayout水平重力setGravity()无法以编程方式工作

我正在尝试使用conatiner.setGravity()通过代码设置线性布局容器的重力。但是它不起作用,但是当通过xml完成 时它正在起作用。下面是我的布局

回答 3 投票 0

如何在线性布局中对齐按钮(viewpager点指示器)

我想为ViewPagerIndicator使用类似的布局,我已经使用了线性布局,并为跳过和下一个使用了平面按钮。从下面的代码中,我正在获得输出,因为我需要这里的帮助。这里...

回答 1 投票 1

我们可以在ConstraintLayout Android中使用RelativeLayout或LinearLayout

我正在开发一个android应用程序,我习惯于相对/线性布局,但是现在我决定使用ConstraintLayout。我是ConstraintLayout的新手。我正在在线阅读一些文档,我也有...

回答 2 投票 0

Android:如何将ImageView对齐到TextView的右边,并确保ImageView始终可见

我需要具有两个视图的Android布局。第一个视图是TextView,第二个视图是ImageView。 ImageView应该始终与TextView的右侧对齐。 TextView应该...

回答 1 投票 0

如何从父级LinearLayout中分离出具有weight属性的2个LinearLayouts

我有一个布局xml文件,其中包含带有2个子LinearLayouts的LinearLayout。我想分开孩子,所以我将它们放在2个布局xml文件中,然后在...

回答 1 投票 0


findViewById()对于夸大的布局返回null

我有一个活动及其布局。现在,我需要从另一个布局menu_layout.xml添加LinearLayout。 LayoutInflater充气机;充气=(LayoutInflater)this.getSystemService(Context ....

回答 2 投票 1

您如何在ScrollView中将ConstraintLayout添加到适合整个屏幕的LinearLayout中?

我希望能够在LinearLayout中滚动,其中每个元素都是适合整个屏幕的ConstraintLayout。我已经尝试过在每个布局中为layout_height设置多个值,但似乎什么都没有...

回答 2 投票 0

LinearLayout中的单独子元素

我尝试在LinearLayout中将Childs分开,因此看起来像Apple版本中的Childs。孩子们总是在一起,请参见此处,我为线性布局制作了自定义背景。 ...

回答 1 投票 0

LinearLayout android layout_height

[帮我实现XML布局。我在活动中有三个LinearLayout,所有LinearLayout的位置均为垂直(从上到下),而我的LinearLayout位置的第一个LinearLayout则为android:layout_height =“ ...

回答 5 投票 1

© www.soinside.com 2019 - 2024. All rights reserved.