android-layout 相关问题

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

如何去掉按钮后面的边框?

我的应用程序按钮后面有一个灰色边框,我该如何删除它? 我这样定义 ImageButton: 我的应用程序按钮后面有一个灰色边框,如何删除它? 我这样定义ImageButton: <ImageButton android:id="@+id/btn_photo_lib" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="startPhotoLibAction" android:src="@drawable/library_blau_2" /> 你必须使用style="?android:attr/borderlessButtonStyle": <ImageButton android:id="@+id/btn_photo_lib" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="startPhotoLibAction" android:src="@drawable/library_blau_2" style="?android:attr/borderlessButtonStyle"/> 试试这个: <ImageButton android:id="@+id/btn_photo_lib" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="startPhotoLibAction" android:background="@android:color/transparent" android:src="@drawable/library_blau_2" /> 简单易行的方法是 android:background="?android:attr/selectableItemBackground" 我发现这个效果很好: android:背景=“@null” 只需将图像视图的背景更改为透明,如下所示: <ImageButton android:id="@+id/btn_photo_lib" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/transparent" <----- Set background. android:onClick="startPhotoLibAction" android:src="@drawable/library_blau_2" /> OR 您可以只设置背景,不需要应用透明色。 <ImageButton android:id="@+id/btn_photo_lib" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/download" <--- set only the background android:onClick="startPhotoLibAction" /> 试试这个 样式 =“?android:attr / borderlessButtonStyle” 在您的按钮选项卡中 你可以试试这个简单的 android:background=""

回答 7 投票 0

Android 在图像上添加 traslucid 覆盖层

我是android初学者。我正在开发一个应用程序,我想要这样的效果: 我认为它是一个背景图像、一个透明颜色的叠加层和一个文本视图。 我的布局是这样的: 我是 Android 初学者。我正在开发一个应用程序,我想要这个效果: 我认为它是一个背景图像,一个带有透明颜色的叠加层,以及一个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="match_parent" > <ImageView android:id="@+id/backgroundImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:contentDescription="Description" /> <ImageView android:id="@+id/overlay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:background="#AAFF0000" android:contentDescription="Description" /> <TextView android:id="@+id/textoOpcion" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="TextView" /> </RelativeLayout> 但这行不通。 有什么办法吗? 尝试这样我希望它对你有用.. 此图像是通过将 textview 背景颜色设置为 #44ff0000 来存在的 u 可以通过将颜色代码 00 的前两个值更改为 ff 来改变颜色的不透明度 #44ff0000 这里 44 是颜色 ff0000 的不透明度 <?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="match_parent" > <ImageView android:id="@+id/backgroundImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:contentDescription="Description" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/textoOpcion" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/backgroundImage" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignRight="@+id/backgroundImage" android:background="#44000000" android:gravity="bottom" android:text="TextView" android:textColor="#ffffff" /> </RelativeLayout> 尝试以下操作。我发现 FrameLayout 对于合成类型的内容效果更好,只需在 TextView 本身上设置背景即可 - 不需要单独的 ImageView。 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textoOpcion" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:background="@color/whatever_you_like" android:text="TextView" /> <ImageView android:id="@+id/overlay" android:layout_width="match_parent" android:layout_height="match_parent" android:contentDescription="Description" android:src="@drawable/drawablewithYourSemiTransparentColor" /> </FrameLayout> 我的解决方案: 我添加了一个 view 来查看叠加颜色,并将 textView 居中 在@M-S-Gadag 的解决方案中,我无法将文本居中: 但我想要这个: 制作第二张图片的代码: <?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="match_parent" > <ImageView android:id="@+id/backgroundImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:contentDescription="Description"/> <View android:id="@+id/overlay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/backgroundImage" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignRight="@+id/backgroundImage" android:background="#99FF0000" /> <TextView android:id="@+id/textoOpcion" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textSize="21sp" android:textColor="#ffffff" /> </RelativeLayout> 编辑 <?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="match_parent" > <ImageView android:id="@+id/backgroundImage" android:layout_width="250dp" android:layout_height="250dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:contentDescription="Description" /> <View android:id="@+id/overlay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/backgroundImage" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignRight="@+id/backgroundImage" android:background="#99FF0000" /> <TextView android:id="@+id/textoOpcion" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/backgroundImage" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignRight="@+id/backgroundImage" android:gravity="center" android:text="map" android:textColor="#ffffff" android:textSize="21sp" /> </RelativeLayout> 我确信代码可以更好,但是这个可行。

回答 3 投票 0

无法向 ScrollView 添加页脚 - Android

我目前正在开发移动应用程序,当我尝试将页脚放在 ScrollView 下时遇到问题。 这是我的代码: 我目前正在开发移动应用程序,当我尝试将页脚放在 ScrollView 下时遇到问题。 这是我的代码: <RelativeLayout android:id="@+id/RelativeLayout01" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <RelativeLayout android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/bottomcontent" android:orientation="vertical" android:background="@drawable/border"> //the footer is added dynamically </RelativeLayout> <ScrollView android:layout_weight="1" android:id="@+id/scroller" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/contentcontainer"> <LinearLayout android:id="@+id/scrollcontentcontainer" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> //the content is added dynamically from a layout template </LinearLayout> </LinearLayout> </ScrollView> </RelativeLayout> ScrollView的内容是一组相对布局,里面有一些按钮和文本视图。它基于我多次膨胀的布局。 页脚只是一个 LinearLayout,其中也有一些按钮。 问题是我尝试了在互联网上找到的所有不同的解决方案,但没有一个有效。就我而言,页脚卡在 ScrollView 的内容下方,而不是 ScrollView 本身下方,因此我必须向下滚动,直到内容结束才能到达页脚。但页脚应该保留在屏幕底部...... 我也尝试了这些解决方案,但没有任何效果: http://www.javacodegeeks.com/2013/10/android-fixed-header-and-footer-with-scrollable-content-layout-example.html (当我尝试这个时,我在屏幕顶部有一个页脚,没有其他东西......) http://www.byteslounge.com/tutorials/android-fixed-header-and-footer-with-scrollable-content-layout-example 和其他一些(也不起作用!) 我也尝试了所有可能的东西,比如使用重力、重量、fillViewPort、对齐到底部......但不可能得到预期的结果。 最小API设置为14,我使用Android Studio。 编辑1: 可绘制边框: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:bottom="-2dp" android:left="-2dp" android:right="-2dp" android:top="2dp"> <shape android:shape="rectangle" > <stroke android:width="1dp" android:color="#000000" /> <solid android:color="#3b010101" /> <padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp" /> </shape> </item> </layer-list> 您可以尝试以下方法,我在 ScrollView 中添加 RelaveLayout 时也遇到了麻烦。 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent"> <RelativeLayout android:id="@+id/bottomcontent" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="@drawable/border"> <!---add something there eg:--> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Test"/> </RelativeLayout> <ScrollView android:id="@+id/scroller" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@id/bottomcontent" android:layout_alignParentTop="true"> <LinearLayout android:id="@+id/contentcontainer" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:id="@+id/scrollcontentcontainer" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> </LinearLayout> </LinearLayout> </ScrollView> </RelativeLayout> . 我在本文档中找到了以下内容。这肯定会导致问题 注意:在平台版本 17 及更低版本中,RelativeLayout 受到 一个测量错误,可能会导致子视图被测量 MeasureSpec 值不正确。 (参见MeasureSpec.makeMeasureSpec 更多详细信息。)当relativelayout容器被 放置在滚动容器中,例如 ScrollView 或 水平滚动视图。如果自定义视图未正确配备 使用 MeasureSpec 模式进行测量 UNSPECIFIED 被放置在 relativelayout,无论如何,这都会像relativelayout一样默默地工作 将传递一个非常大的 AT_MOST MeasureSpec 相反。 此行为已为设置的应用程序保留 android:targetSdkVersion="17" 或更旧的清单的使用-sdk 兼容性标记。面向 SDK 版本 18 或更高版本的应用程序将 接受正确的行为

回答 1 投票 0

撰写:在行布局中换行文本,而不是将同级文本推出

我正在尝试 Jetpack Compose,但 Row 的行为让我感到困惑。我在图标按钮旁边有一个文本,我希望图标按钮锚定到最小宽度 o...

回答 3 投票 0

向上滚动 reyclerview android 时项目正在更新?

我正在制作一个应用程序,其中我必须将数据插入到reyclerview中,recyclerview工作正常,但问题是当我向上滚动适配器时重新更新数据,所以要解决这个问题...

回答 1 投票 0

Compose TextField 明确了获得焦点的价值

我有一个可组合函数,可以显示 2 个文本字段。这是我的代码: 有趣的CreateEntryItem() { var wordA by Remember { mutableStateOf("") } var wordB by Remember { mutableStat...

回答 2 投票 0

Android Studio 上的模糊背景

我正在开发一个需要登录页面的项目 因此,在登录页面中,我要求 android studio 中的背景是模糊的。 我只想背景模糊,而不是其他元素......

回答 1 投票 0

android 电视设置焦点转换速度

我有一个电视应用程序。我在主屏幕上有很多视图。我想设置按住向下按钮时的对焦速度。正常情况下都这么快啊我想减慢焦点在视图之间的转换......

回答 1 投票 0

如何在 PreviewView Android Compose 中绘制抠图?

我正在创建一个 QR 扫描仪,其中预览视图除了中心方形部分之外都是模糊的,我能够模糊 PreviewView,但无法想出一种方法来取消模糊中心切口部分。 AndroidView...

回答 1 投票 0

如何在线性布局(它是另一个线性布局的子级)中均匀分布视图?

我正在尝试设计一个基本上由以下内容组成的布局 线性布局(水平) 线性布局(垂直) 文本视图 文本视图 图像视图 (垂直结束) 线性布局(垂直...

回答 4 投票 0

我的布局中发生了冗余重组。为什么即使输入没有改变它也会重新组合?

我有一个 SnapshotStateMap,用于跟踪布局中的更新,该地图存储在视图模型中。 该网站称: val roundState = viewModel.roundState 对于(索引为 0 直到尝试...

回答 1 投票 0

Android Studio - 未显示布局预览(安全管理器已弃用)

我在一段时间后打开了一个Android项目,布局预览没有显示任何内容: 我正在使用 Android Studio Hedgehog | 2023.1.1 补丁 1 我还注意到这个文件中有 3 个错误。一个...

回答 1 投票 0

在片段上动态切换视图

我怎样才能实现这个目标? 没有显示任何视图... @覆盖 public View onCreateView(LayoutInflater inflater, ViewGroup 容器, 捆绑已保存实例状态) { 查看 v = 充气机。

回答 1 投票 0

java.lang.NoClassDefFoundError:解决失败:Landroid/support/v4/animation/AnimatorCompatHelper

将Android Studio更新至2.3版本后。每次我滑动 ViewPager 时,我都会收到此错误并且应用程序崩溃: 03-23 17:19:19.437 28523-28523/? E/AndroidRuntime:致命异常:mai...

回答 11 投票 0

kundli 应用程序的自定义用户界面

我正在开发一个占星术Android应用程序,我必须创建一个UI来在这个几何UI中显示占星术结果。 示例应用程序屏幕: 我们怎样才能做到这一点?我需要相同的屏幕。

回答 1 投票 0

Android - 用于捕获视图属性更改的监听器(例如 android:layout_marginTop)

在Android中,您可以创建一个监听器来捕获视图属性(宽度/高度/边距/相对于屏幕顶部的位置)的变化吗? 我想在layout_marginT时触发一个事件...

回答 2 投票 0

如何在Android应用程序中使用深色和浅色主题

我刚刚开始学习Android中的主题概念,但我在练习的应用程序中遇到了有线情况,我尝试通过设置主题编程来应用深色和浅色模式功能...

回答 1 投票 0

android 中 ListView 项目的边距

我正在尝试(徒劳地)为我的 ListView 项目添加边距。我尝试在下面的相对布局中添加边距值,但无论我做什么,我似乎得到的只是每个项目之间有一条 1px 的线。 什...

回答 6 投票 0

实现新 API SplashScreen 后 DialogFragment 的边距/填充问题

我在我的应用程序上添加了新的 Splashscreen API (androidx.core:core-splashscreen:1.0.0-rc01),之后我的边距/填充被破坏,但仅适用于我的启动器活动 (MainActivity),特别是对于 di.. .

回答 2 投票 0

LinearLayout 不显示所有 ListView,只显示一个孩子

我有一些数据将显示在 ListView 中。问题是一切都很顺利,但 ListView 或 LinearLayout 没有足够的扩展来显示 CustomListV 的所有子项...

回答 1 投票 0

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