android-layout 相关问题

布局定义用户界面的可视结构,例如活动,片段或应用程序窗口小部件的UI。

从 Kotlin 中的文本更改事件添加 ListViewItem

如果用户在 ListViewItem 文本中键入:“添加新项目”我想添加一个新项目。 到目前为止,这是我的代码: 类 DataModel 内部构造函数( var 检查:布尔值, var item描述:...

回答 1 投票 0

Android - 无法按预期设置按钮边框

我前几天刚开始学习Android。今天当我玩 Button 时,我注意到我无法按预期设置边框。 下面的 xml 文件: Activity_main.xml 中的按钮部分:...

回答 4 投票 0

向 Android 导航抽屉添加图标?

我正在创建一个实现 Android 新导航抽屉布局的应用程序。可以在此处和此处找到此布局的文档。 在设计文档以及 n...

回答 4 投票 0

为什么我的卡片视图在 Android Studio 中超出了整个宽度?

我正在使用此卡片视图(蓝色)和回收器视图中的另一个卡片视图来显示发送和接收的消息。 但是卡片视图(蓝色)覆盖了整个宽度,正如您在图片中看到的那样,我无法...

回答 1 投票 0

默认显示的 Getter:显示!'已弃用。在 Java 中已弃用

我需要屏幕的宽度。但最近发现 Android defaultDisplay 已弃用,并显示消息: defaultDisplay 的 Getter:显示!'已弃用。在 Java 中已弃用 代码: val 显示指标 =

回答 11 投票 0

为什么我的布局在物理设备上会崩溃?

我正在学习 android studio,参加 Udemy 课程。 课程本身一切都很好,我也相处得很好。唯一的问题是,我的笔记本电脑很弱,比如 8GB 的内存很弱。所以运行模拟器

回答 2 投票 0

有没有办法删除android中按钮的默认样式?

我在 android studio xml 文件中有按钮,当我更改它时它不会改变形状和颜色 我不想创造自己的风格 看起来怎么样 这是我的代码: 我在 android studio xml 文件中有按钮,当我更改它时,它的形状和颜色没有改变 我不想创造自己的风格 看起来怎么样 这是我的代码: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".fragments.PlantsListFragment"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:background="#1F1F27"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/spaces" android:textColor="@color/white" android:textSize="20sp" android:layout_centerInParent="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/rounded_square" android:backgroundTint="#1C2F33" /> </RelativeLayout> </FrameLayout> 如果需要的话,这里还有我的 rounded_square.xml 文件: <?xml version="1.0" encoding="utf-8"?> <shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#1C2F33" /> <corners android:radius="30dp" /> </shape> 我希望这个按钮的颜色为“#1C2F33”并且我希望它有圆角 不要使用Button,而是使用AppCompatButton,然后对其应用可绘制的背景形状。您也不需要背景色调,因为颜色已经在可绘制形状中指定。 <androidx.appcompat.widget.AppCompatButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/rounded_square" /> 还有更多背景信息。 您不是删除样式,而是替换它。 默认情况下,Android 中的每个控件都继承自其应用程序(您在清单中指定的 launchTheme)或活动的主题(也在清单中指定)传递的主题。 控件可以有自己的样式,您只需创建一个样式然后将其应用到您的控件即可。该主题将自动替换从其父上下文(活动/应用程序)传递下来的主题。 如果您使用 Material 主题,请记住仅使用 AppCompat 控件。 AppCompat 允许更轻松的自定义,而不是基本控件(例如按钮)。

回答 1 投票 0

在 React Native 中嵌入原生 Android Activity

我正在使用这个库在 android 中以 React Native 方式制作标签栏 https://github.com/aksonov/react-native-tabs 我必须在其中一个页面中打开本机 Android 活动。 可以请告诉我吗...

回答 1 投票 0

如何让Android应用程序认为设备处于水平模式

所以基本上我想在android电视上运行一些本机android应用程序,一些应用程序只是不能在水平模式下工作,除非应用程序有视频并且是全屏的,所以应用程序是否有可能认为...

回答 2 投票 0

Android:手机和平板电脑之间很难实现相同的布局比例/长宽比

当我说“相同的布局比例”时,我主要指的是文本大小,但也指一般的视图。 我一直读到 sp 文本大小单位与屏幕无关,但这不是

回答 1 投票 0

TextInput 在小屏幕手机上显示太窄

在以下 xml 中,“message_entry”在小屏幕 (240 x 320) 上显示太窄,但在较大屏幕 (480 x 640) 上显示良好。 在以下 xml 中,“message_entry”在小屏幕 (240 x 320) 上显示太窄,但在较大屏幕 (480 x 640) 上显示良好。 <androidx.cardview.widget.CardView android:id="@+id/reply_bar_card" android:layout_width="match_parent" android:layout_height="wrap_content" app:cardBackgroundColor="@color/replyBarCard" app:cardCornerRadius="24dp" app:cardElevation="5dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="24dp"> <ProgressBar android:id="@+id/send_progress" style="@style/Widget.AppCompat.ProgressBar.Horizontal" android:layout_width="match_parent" android:layout_height="3dp" android:indeterminate="true" android:visibility="invisible" /> <HorizontalScrollView android:id="@+id/attached_image_scroller" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="@dimen/message_list_padding" android:layout_marginEnd="@dimen/message_list_padding" android:paddingTop="8dp" android:paddingBottom="8dp" android:scrollbars="none" android:visibility="gone"> <LinearLayout android:id="@+id/attached_image_holder" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="12dp" android:layout_marginEnd="12dp" android:orientation="horizontal" /> </HorizontalScrollView> <LinearLayout android:id="@+id/smart_reply_container" android:layout_width="match_parent" android:layout_height="56dp" android:layout_marginStart="@dimen/message_list_padding" android:layout_marginEnd="@dimen/message_list_padding" android:gravity="end" android:orientation="horizontal" android:visibility="gone"> <ImageButton android:id="@+id/close_smart_replies" android:layout_width="32dp" android:layout_height="48dp" android:layout_gravity="center_vertical" android:layout_marginStart="8dp" android:background="?selectableItemBackgroundBorderless" android:clickable="true" android:contentDescription="@string/use_smart_replies" android:src="@drawable/ic_cancel" android:tint="@color/secondaryText" /> <LinearLayout android:id="@+id/smart_reply_suggestions_container" android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginEnd="12dp" android:layout_weight="1" android:gravity="end" android:orientation="horizontal" /> </LinearLayout> <LinearLayout android:id="@+id/send_bar" android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginStart="@dimen/message_list_padding" android:layout_marginEnd="@dimen/message_list_padding" android:alpha="0" android:clipToPadding="false" android:gravity="center_vertical|start" android:orientation="horizontal" android:padding="8dp" android:translationY="-32dp"> <ImageButton android:id="@+id/select_sim" android:layout_width="32dp" android:layout_height="48dp" android:background="?selectableItemBackgroundBorderless" android:clickable="true" android:contentDescription="@string/select_sim" android:src="@drawable/ic_sim" android:tint="@color/secondaryText" android:visibility="gone" /> <ImageButton android:id="@+id/view_scheduled_messages" android:layout_width="32dp" android:layout_height="match_parent" android:background="?selectableItemBackgroundBorderless" android:clickable="true" android:contentDescription="@string/view_scheduled_messages" android:src="@drawable/ic_schedule_small" android:tint="@color/secondaryText" android:visibility="gone" /> <FrameLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginEnd="8dp"> <ImageButton android:id="@+id/attach" android:layout_width="32dp" android:layout_height="48dp" android:layout_gravity="center_vertical|start" android:background="?selectableItemBackgroundBorderless" android:clickable="true" android:contentDescription="@string/attach" android:src="@drawable/ic_attach" android:tint="@color/secondaryText" /> <TextView android:id="@+id/text_counter" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom|center_horizontal" android:layout_marginBottom="2dp" android:gravity="center_horizontal" android:textColor="@color/secondaryText" android:textSize="12sp" /> </FrameLayout> <com.google.android.material.textfield.TextInputEditText android:id="@+id/message_entry" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@null" android:backgroundTint="@color/drawerBackground" android:hint="@string/type_message_to" android:imeOptions="actionSend|flagNoExtractUi" android:inputType="textCapSentences|textAutoCorrect|textMultiLine" android:maxLines="@integer/message_list_fragment_line_entry_count" android:minHeight="40dp" android:padding="8dp" android:paddingStart="8dp" android:paddingEnd="18dp" android:scrollHorizontally="false" android:textSize="16sp" /> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:contentDescription="@string/send_message" android:src="@drawable/ic_send" app:elevation="0dp" app:fabSize="mini" app:rippleColor="@android:color/white" /> </LinearLayout> <ViewStub android:id="@+id/attach_stub" android:layout_width="match_parent" android:layout_height="@dimen/attach_menu_height" android:layout="@layout/view_attach_menu" /> </LinearLayout> </androidx.cardview.widget.CardView> 小屏幕:(添加红框用于说明) 大屏幕:(添加红框作为说明) 预期的行为就像大屏幕,其中“message_entry”尽可能宽。为什么“message_entry”在小屏幕上那么窄?我该如何解决它? 原来是因为dimens.xml文件夹下有多个res文件造成的。这用于支持多种屏幕尺寸,在较小屏幕的 dimens.xml 中,有 <dimen name="message_list_padding">96dp</dimen>。一旦更改为0dp,布局就如预期的那样。 有关多个 dimens.xml 文件的更多信息,请参阅此答案中的#2。

回答 1 投票 0

如何将图像放在按钮上android studio

我有一个512x512px的齿轮png图像(用于设置),我希望它放在一个按钮上。 我试图在可绘制的目录中创建一个目录以保持事物井井有条,但这不起作用,所以我把...

回答 1 投票 0

在Android中的列表视图和网格视图之间高效切换,平滑过渡

我正在尝试实现一个视图切换,使用户能够在Android中的“列表视图”和“网格视图”之间切换。然而,我已经做到了这一点,但我对结果并不满意

回答 1 投票 0

为什么 Android Studio 在我的项目中使用自定义样式时出现问题?

在布局中引用我的项目自定义样式之一时,我都会收到有关无关输入的语法错误。语法错误 样式仍然正确应用于布局和项目

回答 1 投票 0

如何以编程方式在聊天窗口中显示位置消息,就像android中的whatsapp一样?

我正在开发一个聊天应用程序。用户可以像 Whatsapp 一样发送位置信息。 (我不是在谈论共享实时位置功能)。对于这个要求,我使用了谷歌地点选择器......

回答 4 投票 0

如何解决android Edittext光标位置问题与对齐跨度

我正在开发简单的android编辑器应用程序。因为我使用了对齐跨度。如果我将对齐方式正常(左)更改为相反(右)或居中,则光标无法正确渲染。 设备:N...

回答 1 投票 0

ConstraintLayout 中 app:layout_constrainedWidth 有什么用?

我正在尝试查看在 ConstraintLayout 中使用 app:layout_constrainedWidth="true" 的示例,但我并不理解此属性的使用。在什么场合我应该使用这个

回答 1 投票 0

回收站视图中自动调整图像卡视图

我正在研究RecyclerView以在CardView中显示图像。 我使用 GridLayoutManager 并且在每行中指定了 3 个项目: mLayoutManager = new GridLayoutManager(context,3); 问题:图像...

回答 2 投票 0

Android Studio 中缺少布局 XML 文件夹

问题: 布局 XML 文件夹丢失? 怎么添加?

回答 4 投票 0

如何在 Android Kitkat 中调整 AppCompatRadioButton 的 DrawableLeft 大小?

在 Xamarin Android 应用程序中,我有一个 AppCompatRadioButton,其 drawableLeft 属性设置为 @drawable/person_resized: 在 Xamarin Android 应用程序中,我有一个 AppCompatRadioButton,其 drawableLeft 属性设置为 @drawable/person_resized: <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.AppCompatRadioButton android:id="@+id/MyRadioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Selection 1" android:textSize="24dp" android:drawableLeft="@drawable/person_resized" android:drawablePadding="5dp" /> </RadioGroup> drawable/person_resized.xml 是一个图层列表可绘制对象,我用它来缩小 drawable/person.png 图像: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/person" android:width="22dp" android:height="22dp" /> </layer-list> 当此视图显示在 Android N 模拟器上时,它的行为正常。 但是在我的 Android Kitkat(4.4.4) 设备中,图像大小不正确。 这是我在 Android N 中得到的: 这是我在 Android Kitkat 中得到的: 这是怎么回事? 我尝试了以下方法来缩小 Android Kitkat 中的 drawableLeft 的大小,但 都不起作用: 使用ScaleDrawable缩小可绘制对象,同时确保SetLevel,这实际上允许调整可绘制对象的大小,但不受控制;无论我提供什么缩放系数,调整大小的图像始终是相同的较小尺寸 从可绘制对象中获取位图,调整其大小并创建一个新的位图可绘制对象,但这会使图像消失 使用插入可绘制对象,与使用图层列表相同,使图像以其原始大小显示 根据Mahmoud Mortda指出的这个答案,Android Kitkat 中的一些功能障碍导致图层列表调整大小被忽略。 所以基本上你必须自己做,以下是我所做的: 我创建了两个文件 layout-v21/radio_group.xml 和 layout/radio_group.xml,前者将用于运行至少 Lollipop (SDK 21) 的 Android 设备,后者将用于包括 KitKat 在内的其余设备。 layout-v21/radio_group.xml 包含通过 RadioGroup 调整大小的图像的 layer-list: <?xml version="1.0" encoding="utf-8"?> <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.AppCompatRadioButton android:id="@+id/MyRadioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Selection 1" android:textSize="24dp" android:drawableLeft="@drawable/person_resized" android:drawablePadding="5dp" /> </RadioGroup> layout/radio_group.xml 包含一个 RadioGroup,带有由 ImageView 和 TextView 制成的“手工制作”标签: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:id="@+id/RadGroup"> <android.support.v7.widget.AppCompatRadioButton android:id="@+id/MyRadioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="24dp" /> </RadioGroup> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_toRightOf="@+id/RadGroup" android:layout_centerVertical="true"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/icon" android:layout_width="22dp" android:layout_height="22dp" android:src="@drawable/person" android:layout_alignParentLeft="true" android:layout_centerVertical="true" /> <TextView android:id="@+id/label1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_toRightOf="@+id/icon" android:layout_centerVertical="true" android:textSize="24dp" android:textColor="@color/black" android:text="Selection 1" /> </RelativeLayout> </RelativeLayout> 这里使用 ImageView 让我可以有效地调整图像大小。 最后,在包含 RadioGroup 的 xml 布局中,只需包含 @layout/radio_group,SDK 将加载针对 Android 版本的正确布局: <include layout="@layout/radio_group"/> 添加RadioButton。 <androidx.appcompat.widget.AppCompatRadioButton android:id="@+id/dialog_pedido_item_produto_desconto_radio_button_desconto" android:layout_width="wrap_content" android:layout_height="wrap_content" android:buttonTint="@color/red_600" android:bufferType="spannable" android:gravity="center" android:drawableStart="@drawable/ic_arrow_downward_red_24dp" android:checked="true" android:padding="@dimen/dp_5" android:text="Desconto" />

回答 2 投票 0

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