android-layout 相关问题

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

在膨胀之前获取 xml 中声明的属性值

我正在创建一个扩展 MaterialButton 的自定义按钮 MyButton。用例是按钮有大和小 2 种尺寸,大按钮将是全宽(类似于 match_parent)并且 s...

回答 1 投票 0

如何调整背景图像大小以匹配布局?

我有一个问题,如何在 android studio 中调整背景图像的大小以匹配整个布局,例如: 我有一个默认为横向的可绘制对象,但我的布局是水平的,我想要

回答 4 投票 0

如何将xml布局转为PDF报告?

在此处输入图像描述我已经在 android studio 中以 XML 创建了一个报告布局。单击布局上的“生成”按钮后,我需要将布局转换为 PDF 格式。有没有

回答 2 投票 0

在膨胀之前获取在 xml 中声明的按钮尺寸

我正在创建一个扩展 MaterialButton 的自定义按钮 MyButton。用例是按钮有大和小 2 种尺寸,大按钮将是全宽(类似于 match_parent)并且 s...

回答 1 投票 0

如何在mp4视频文件中添加MOOV原子[已关闭]

我正在开发实时设备到Android中的服务器流媒体。我能够在服务器上以字节为单位发送数据,但是当我在服务器 VLC 上录制期间播放该文件时,会说找不到 MOOV 原子。经过...

回答 7 投票 0

如何更改 Material 3 android xml 的警报对话框的颜色

我想更改材质3警报对话框的容器颜色 我尝试使用官方文档中的内容 但我无法更改颜色,容器的背景颜色仍然是粉红色/紫色 ...

回答 1 投票 0

为什么我的DialogFragment在Android 11中没有全屏显示?

我有一个对话框片段,用于从列表中进行选择。我在全屏模式下有这个,它在 11/ API 30 之前一直有效。但是,现在在 11 中,它开始出现经典的“不...

回答 1 投票 0

如何删除两个 ImageView 之间的间距

假设我正在我的应用程序中制作新闻布局。第一个 ImageView 应该是主要的,这就是为什么它较大的 ImageView 和其他新闻将由较小的 ImageView 呈现。 所以每条新闻都有图像...

回答 1 投票 0

不同屏幕方向的不同列表视图布局

我有一个视图,我想在其上放置两个 ListView,这两个 ListView 的位置根据屏幕方向彼此相邻。它看起来像这样: 横屏方向:

回答 3 投票 0

工具栏不允许在其中使用匹配父布局

我设计了一个工具栏,但它不允许我制作匹配父级布局。它的左侧被锁定,不允许我将 TextView 放在那里,但右侧表现良好; 我看过...

回答 2 投票 0

Textcell 在模拟器上显示,但在 Android 上不显示

我的 xaml 在模拟器中正确显示时遇到问题,但在打包并安装到我的 Android 手机上时却出现问题。另外,堆栈布局中的普通标签根本不会显示在我的

回答 1 投票 0

BottomSheetDialog 与 EditText(删除键盘下的背景)

我有一个 BottomSheetDialog,用作评论部分。在它的底部,有一个 EditText 视图,使用户能够添加新评论。 当键盘出现时,问题就出现了——du...

回答 1 投票 0

如何从手机浏览器打开深层链接?

我为我的应用程序创建了一个深层链接,myapp://video 或者说我还添加了 uber:// 但是当我从 Chrome 浏览器打开这些链接时,它会带我去谷歌,它不会将此视为一个链接,那么如何...

回答 7 投票 0

Android 在视图之间绘制水平线

我的布局如下: 我的布局如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" style="@style/behindMenuItemLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Twitter Feeds" android:textStyle="bold" /> <ListView android:id="@+id/list" android:layout_width="350dp" android:layout_height="50dp" /> <TextView android:id="@+id/textView1" style="@style/behindMenuItemLabel1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="1dp" android:text="FaceBook Feeds" /> <ListView android:id="@+id/list1" android:layout_width="350dp" android:layout_height="50dp" /> </LinearLayout> 我的要求是在TextView和ListView之间画一条水平线 有人可以帮忙吗? 它将在 TextView 和 ListView 之间绘制银灰色线 <TextView android:id="@+id/textView1" style="@style/behindMenuItemLabel1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="1dp" android:text="FaceBook Feeds" /> <View android:layout_width="match_parent" android:layout_height="2dp" android:background="#c0c0c0"/> <ListView android:id="@+id/list1" android:layout_width="350dp" android:layout_height="50dp" /> 您应该使用新的轻量级视图Space来绘制分隔线。 如果您使用 Space 而不是 View,您的布局加载速度会更快。 水平分隔线: <android.support.v4.widget.Space android:layout_height="1dp" android:layout_width="match_parent" /> 垂直分隔线: <android.support.v4.widget.Space android:layout_height="match_parent" android:layout_width="1dp" /> 您还可以添加背景: <android.support.v4.widget.Space android:layout_height="match_parent" android:layout_width="1dp" android:background="?android:attr/listDivider"/> 使用示例: .... <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="One"/> <android.support.v4.widget.Space android:layout_height="match_parent" android:layout_width="1dp" android:background="?android:attr/listDivider"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Two"/> <android.support.v4.widget.Space android:layout_height="match_parent" android:layout_width="1dp" android:background="?android:attr/listDivider"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Three"/> .... 为了使用Space,您应该在build.gradle中添加依赖项: dependencies { compile 'com.android.support:support-v4:22.1.+' } 文档https://developer.android.com/reference/android/support/v4/widget/Space.html 在布局中要分离的视图之间添加类似的内容: <View android:id="@+id/SplitLine_hor1" android:layout_width="match_parent" android:layout_height= "2dp" android:background="@color/gray" /> 希望有帮助:) 创建一次并在需要的地方使用它是一个好主意。 将其添加到您的 styles.xml 中: <style name="Divider"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">1dp</item> <item name="android:background">?android:attr/listDivider</item> </style> 并将其添加到需要行分隔符的 xml 代码中: <View style="@style/Divider"/> 最初由 toddles_fp 回答这个问题:Android Drawing Separator/Divider Line in Layout? 试试这个 <View android:layout_width="match_parent" android:layout_height="2dp" android:background="?android:attr/listDivider"/> 多年之后,终于有一个合适的视图可以在 XML 布局上显示分隔符/分隔线/水平线。为 Android 开发 Material Components 的团队已发布版本 1.5.0-alpha01,其中添加了 MaterialDivider 类。这允许向布局添加分隔线,如前所述。 首先,在 build.gradle 中添加以下内容: implementation 'com.google.android.material:material:1.5.0-alpha01' 然后,在 XML 布局上您可以编写: <com.google.android.material.divider.MaterialDivider android:layout_width="match_parent" android:layout_height="wrap_content"/> 瞧,你有一个分隔器。如果你想自定义分隔线的颜色,有一个xml属性:app:dividerColor。此视图还允许通过样式设置主题。欲了解更多信息,您可以查看此链接。 <View android:id="@+id/view" android:layout_width="match_parent" android:layout_height="2dp" android:background="#000000" /> 对 Bhoomika 接受的答案进行了改进,以获得更精美的外观: <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/black" android:alpha="0.1"/> android:alpha 用于设置视图的不透明度。 您可以将此视图放在您的视图之间来模仿线条 <View android:layout_width="fill_parent" android:layout_height="2dp" android:background="#c0c0c0"/> 试试这个对我有用 <View android:layout_width="1dp" android:layout_height="match_parent" android:background="@color/tw_composer" /> 创建水平线 如果您正在使用 TextView,然后您想放置一行,则使用 View 这样你就可以使用任何颜色,如蓝色、红色或黑色提及背景颜色。 <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/black"></view> 在您希望组件之间有分隔线的每个父级 LinearLayout 中,添加 android:divider="?android:dividerHorizontal" 或 android:divider="?android:dividerVertical。 根据您的LinearLayout的方向在它们之间选择合适的。 据我所知,这个资源样式是从Android 4.3开始添加的。 试试这个 <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/darker_gray"/> ---->简单的一个 <TextView android:layout_width="match_parent" android:layout_height="1dp" android:background="#c0c0c0" android:id="@+id/your_id" android:layout_marginTop="160dp" /> 可以指定背景颜色的视图(高度=几个 dpi)。 查看真实代码,它是: <LinearLayout android:id="@+id/lineA" android:layout_width="fill_parent" android:layout_height="2dp" android:background="#000000" /> 请注意,它可以是任何类型的 View。 如果您不想仅使用额外的视图来显示下划线。在您的 textView 上添加此样式。 style="?android:listSeparatorTextViewStyle" 缺点是它会添加额外的属性,例如 android:textStyle="bold" android:textAllCaps="true" 您可以轻松覆盖它。 对我有用的是 <view android:layout_below="@+id/kaimla_number" android:layout_width="match_parent" android:layout_height="3dp" android:background="@color/golden"></view> <view android:id="@+id/blackLine" android:layout_width="match_parent" android:layout_height="1dp" android:background="#000000" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"/> 应用程序:layout_constraintStart_toStartOf =“父”/> 使用此视图标签,您可以水平或垂直地创建视图,只需更改高度和宽度即可使其水平和垂直。您可以简单地创建水平和垂直线。 这是水平线代码,其中视图的高度是线的厚度。 <View android:id="@+id/view" android:layout_width="match_parent" android:layout_height="1.5dp" android:layout_marginHorizontal="24dp" android:layout_marginTop="20dp" android:background="@color/green" app:layout_constraintTop_toBottomOf="@id/imgChoice" />

回答 19 投票 0

在compose中使用.dp扩展函数之前是否需要将Int解析为dp?

假设我在figma中有一个分辨率为1080x1920的屏幕,然后我添加20px填充,当我用compose重新创建这个布局时,我需要将20解析为dp(使用一些实用函数,例如:val Int.dp:...

回答 1 投票 0

Android:Recyclerview 滚动并出现折叠工具栏问题

在我的应用程序中,我使用 CollapsingtoolbarLayout 和 RecyclerView。两人都在工作。但我在滚动它们时遇到问题。我想要的是每当我直接滚动 RecyclerView 时我想要...

回答 1 投票 0

Android OutlinedBox 样式在 TextInputLayout 中不起作用

我搜索并尝试了很多解决方案,但还是不行。 (仍然显示“FilledBox”样式) 我的代码有什么问题? 输入布局.xml 我搜索并尝试了很多解决方案,但还是不行。 (仍然显示“FilledBox”样式) 我的代码有什么问题? input_layout.xml <com.google.android.material.textfield.TextInputLayout android:theme="@style/Theme.MaterialComponents.Light.NoActionBar" android:id="@+id/text_input_layout" tyle="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" ... > <com.google.android.material.textfield.TextInputEditText android:id="@+id/text_input_edit_text" ... /> </com.google.android.material.textfield.TextInputLayout> styles.xml <style name="AppBaseTheme" parent="android:Theme.MaterialComponents.Light"/> <style name="AppTheme" parent="AppBaseTheme"> <item name="textInputStyle">@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox</item> </style> 你可以尝试这个代码,它对我有用 <com.google.android.material.textfield.TextInputLayout style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="match_parent" android:layout_height="wrap_content" app:boxStrokeColor="@color/bg_blue_tint" app:boxStrokeWidth="2dp" app:boxStrokeWidthFocused="2dp" app:endIconDrawable="@drawable/ic_email" app:endIconMode="custom" app:hintEnabled="false" android:hint="Email" android:layout_marginHorizontal="20dp" android:layout_marginBottom="15dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toBottomOf="parent"> <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="match_parent" android:hint="@string/email" android:maxLines="1" android:imeOptions="actionNext" android:inputType="textEmailAddress" android:textColorHint="@color/hint_color" /> </com.google.android.material.textfield.TextInputLayout> 当聚焦时,这段代码看起来像这样

回答 1 投票 0

Android Widget/View LayoutParams 如何获取?

我正在使用 Android Giraffe,我想从按钮获取 LayoutParams,然后更改其中一个值,然后设置新的参数,如下所示: //获取当前参数 LayoutParams 参数 = 按钮。

回答 1 投票 0

如何以编程方式设置按钮的参数

我正在尝试向这样的布局添加一堆按钮: for( int i = 0; i < 10; i++ ) { Button button = new Button( this ); button.setText( "" + i ); ( ( LinearLayout )dialog.

回答 6 投票 0

Android Button LayoutParams 如何获取?

我正在使用 Android Giraffe,我想从按钮获取 LayoutParams,然后更改其中一个值,然后设置新的参数,如下所示: //获取当前参数 LayoutParams 参数 = 按钮。

回答 1 投票 0

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