android-layout 相关问题

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

使用自己的 png 文件定制可绘制对象会导致 Android 中的 OpenGLRenderer 错误

我在尝试基于自定义 bade png 文件创建自己的 Android 可绘制对象时遇到了大问题。这个问题与我几天前发布的上一个问题类似(并且尚未得到解决...

回答 1 投票 0

drawableStart 不显示drawable

我正在学习android,书中的挑战之一说要自己添加上一个按钮。我做到了,并请朋友帮忙将箭头放在左侧,他做到了,但他可以...

回答 3 投票 0

如何让EditText和Button有这个彩色边框?

如何让EditText带有这个边框,Button也带有这个边框。我找不到用可绘制的方法来做到这一点。我使用 ImageView 来实现这个。但我不能将 ImageView 用于 EditText。怎么才能做到这一点?

回答 1 投票 0

如何在 Jetpack Compose Material 3 中制作支架 FAB?

我正在尝试使用 Jetpack Compose Material 3 制作 Cradled FAB。基于本网站文档中的图像:https://m3.material.io/components/bottom-app-bar/implementation 然而...

回答 4 投票 0

我在android studio中创建了一个底部导航栏,但它在活动栏中没有正确显示

XML 文件 <?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" tools:context=".MainActivity"> <FrameLayout android:id="@+id/flFragment" android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottomNavigationView" android:layout_width="match_parent" android:layout_height="75dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:menu="@menu/bottom_navigation"/> </androidx.constraintlayout.widget.ConstraintLayout> public class MainActivity extends AppCompatActivity { public static final int main=0x7f030004; ActivityMainBinding activityMainBinding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activityMainBinding=ActivityMainBinding.inflate(getLayoutInflater()); setContentView(activityMainBinding.getRoot()); replaceFragment(new homeFragment()); activityMainBinding.bottomNavigationView.setOnItemSelectedListener(item -> { if(item.getItemId()==R.id.home){ replaceFragment(new homeFragment()); } else if(item.getItemId()==R.id.history){ replaceFragment(new historyFragment()); } return true; }); } private void replaceFragment(Fragment fragment){ FragmentManager fragmentManager=getSupportFragmentManager(); FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.history, fragment); fragmentTransaction.commit(); } } 问题是主页片段显示在主页图像上,而不是活动栏上。我已经搜索了所有问题,但找不到解决此问题的问题,并且不知道该怎么办。请帮我解决这个问题 根据我对你的问题的理解,替换后的片段显示在底部导航图标中。 我猜您正在将片段加载到错误的位置(将 fragmentTransaction.replace 映射到错误的元素 id)。 您应该替换框架布局中的片段,而不是历史按钮(我猜这是底部导航栏中的菜单项)。 待更新代码: private void replaceFragment(Fragment fragment){ FragmentManager fragmentManager=getSupportFragmentManager(); FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.flFragment, fragment); fragmentTransaction.commit(); } 希望这个答案能解决您的问题。 以下是片段事务的 .replace 函数的文档:https://developer.android.com/guide/fragments/transactions#java

回答 1 投票 0

如何使用横向和纵向布局?

我有一个活动和几个片段(它们称为fragmentA和fragmentB)。 现在fragmentA需要同时具有纵向和横向布局。 fragmentB 必须保持纵向。活动显示

回答 1 投票 0

修复“文本颜色对比度不足”添加不正确的属性

我的布局中收到“文本颜色对比度不足”警告。当我在警告屏幕中使用“修复”选项时,它向我的文本添加了一个属性 android:hintTextColor...

回答 3 投票 0

对齐单选组内的单选按钮

我正在开发一个 Android 3.1 平板电脑应用程序并在这里提出这个问题,因为我在代码中没有找到任何有效的答案(或示例)。 我有以下代码: 我正在开发一个 Android 3.1 平板电脑应用程序并在这里提出这个问题,因为我在代码中没有找到任何有效的答案(或示例)。 我有以下代码: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" > <LinearLayout android:id="@+id/materialsLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <!-- 0 . Título del fragment --> <TextView android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight=".5" android:gravity="center_horizontal" android:text="@string/layout_title_quantity" android:textAppearance="?android:attr/textAppearanceLarge" /> <!-- 1. Texto --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/layout_qty_size_carton" android:textAppearance="?android:attr/textAppearanceMedium" /> <!-- 2. Texto --> <LinearLayout android:layout_width="match_parent" android:layout_height="40dip" android:layout_gravity="center" android:orientation="horizontal" android:weightSum=".45" > <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight=".1" android:gravity="right" android:text="@string/layout_req_po" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight=".05" android:text="@string/layout_qty_carton" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/qtyPerCartonTxt" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight=".05" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight=".01" android:gravity="center" android:text="@string/layout_slash" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight=".05" android:text="@string/layout_cartoon_size" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/cartonSizeTxt" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight=".05" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight=".01" android:gravity="center" android:text="@string/layout_slash" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight=".03" android:text="@string/layout_weight" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/cartonWeightTxt" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight=".05" android:textAppearance="?android:attr/textAppearanceMedium" /> </LinearLayout> <!-- 3. Titulo tabla --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/layout_actual_finding" android:textAppearance="?android:attr/textAppearanceMedium" /> <!-- 4. Cabecera tabla --> <LinearLayout android:layout_width="match_parent" android:layout_height="40dip" android:layout_gravity="center" android:orientation="horizontal" android:weightSum=".5" > <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight=".07" android:gravity="center" android:text="@string/layout_cartoon_number" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight=".07" android:gravity="center" android:text="@string/layout_actual_qty" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight=".07" android:gravity="center" android:text="@string/layout_actual_size" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight=".07" android:gravity="center" android:text="@string/layout_actual_weight" android:textAppearance="?android:attr/textAppearanceMedium" /> <Button android:id="@+id/btnAddNewActPckCtr" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight=".05" android:onClick="onAddNewActPckCtrClick" android:text="@string/btn_add_new" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="40dip" android:layout_gravity="center" android:orientation="horizontal" android:weightSum=".5" > <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight=".07" android:gravity="right" android:text="@string/layout_result" android:textAppearance="?android:attr/textAppearanceMedium" /> <RadioGroup android:id="@+id/rGroupResQTYOnline" android:layout_width="0dip" android:layout_height="match_parent" android:layout_gravity="right" android:layout_weight=".07" android:orientation="horizontal" > <RadioButton android:id="@+id/rResQTYOnlineYes" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="right" android:text="@string/layout_yes" /> <RadioButton android:id="@+id/rResQTYOnlineNo" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="left" android:text="@string/layout_no" /> </RadioGroup> <RadioGroup android:id="@+id/rGroupResSzOnline" android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight=".07" android:orientation="horizontal" > <RadioButton android:id="@+id/rResSzOnlineYes" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="@string/layout_yes" /> <RadioButton android:id="@+id/rResSzOnlineNo" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="@string/layout_no" /> </RadioGroup> <RadioGroup android:id="@+id/rGroupResWgOnline" android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight=".07" android:orientation="horizontal" > <RadioButton android:id="@+id/rResWgOnlineYes" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="@string/layout_yes" /> <RadioButton android:id="@+id/rResWgOnlineNo" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="@string/layout_no" /> </RadioGroup> <Button android:id="@+id/btnTakeQtyOnlinePhoto" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight=".07" android:onClick="onTakePhotoClick" android:text="@string/btn_take_photo" /> </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="40dip" android:layout_gravity="center_horizontal" android:layout_marginLeft="40dip" android:layout_marginTop="40dip" android:layout_weight=".1" android:gravity="left|center_vertical" android:text="@string/layout_photos" android:textAppearance="?android:attr/textAppearanceMedium" /> <Gallery android:id="@+id/quantityOnlineGallery" android:layout_width="fill_parent" android:layout_height="200dip" /> </LinearLayout> </ScrollView> 我正在尝试将单选按钮置于单选组内,但我不知道该怎么做。 我已经尝试过这段代码: <RadioGroup android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:layout_gravity="center|left"/> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center|right" /> </RadioGroup> 但这不起作用。 我该怎么办? 尝试一下这个可能会有所帮助: 将您的收音机组对齐到中心 <RadioGroup android:id="@+id/rGroupResSzOnline" android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight=".07" android:gravity="center" android:orientation="horizontal" > <RadioButton android:id="@+id/rResSzOnlineYes" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="Yes" /> <RadioButton android:id="@+id/rResSzOnlineNo" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="No" /> </RadioGroup> 由于 RadioGroup 覆盖了线性布局,因此您可以像线性布局的子视图一样对齐单选按钮。 如果要将所有子单选按钮对齐到中心:<RadioGroup.... android:gravity="centre" ...> 如果您希望一个单选按钮在结束时启动另一个单选按钮:<RadioButton1... android:layout_weight="1".../> <RadioButton2... android:layout_weight="1".../> 如果你想强制将RadioButton2对齐到最末端,它会为两个RadioButton分配相等的空间,只是不要为其分配layout_weight。 您是否尝试过在RadioGroup中嵌套LinearLayout或RelativeLayout并将RadioButton放入其中?我自己没试过,不知道是否有效。

回答 3 投票 0

如何以编程方式设置主屏幕小部件上使用的形状的描边颜色

所以,我有这个 rounded_corner_shape.xml 所以,我有这个 rounded_corner_shape.xml <shape xmlns:android="http://schemas.android.com/apk/res/android" > <stroke android:width="1dp" android:color="TO_BE_SET_DYNAMICALLY" /> <corners android:radius="8dp" /> </shape> 用于 ip_properties.xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/ip_property_tv_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/rounded_corner_shape" /> </LinearLayout> 然后我想从 RemoteViewsService.RemoteViewsFactory 实现动态设置描边颜色,如下所示: class WifiPropertyViewsFactory: RemoteViewsService.RemoteViewsFactory{ // other overrides... override fun getViewAt(position: Int): RemoteViews = RemoteViews(context.packageName, R.layout.ip_properties) .apply { setTextViewText(R.id.ip_property_tv_1, "some data") // set background rounded corner shape stroke color } } 由于不太了解,我尝试通过RemoteViews.setInt(R.id.ip_property_tv_1, "setBackgroundTint", colorInt)设置,但没有成功。有人知道如何让它发挥作用吗? 尝试此代码 - 文本视图以编程方式更改背景描边颜色 在 setOnClickListener() 方法中使用此代码 edtSelectState.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setStroke(2, Color.RED); edtSelectState.setBackground(gradientDrawable); } });

回答 1 投票 0

内含RecyclerView的动态高度布局

大家。 我正在努力解决这里的布局,其中我有一个用 ConstraintLayout 制作的组件。在这个组件内部,我有一个固定的标题和一个 RecyclerView 就在下面,它应该是...

回答 1 投票 0

错误:xml 文件中缺少类 Android Studio Androidx

如何修复这些缺失的类? 我将项目迁移到 Androidx,但在 xml 文件中出现这些错误(ExpandableHeightGridView、TextView、SliderLayout、StickyScrollView、

回答 1 投票 0

HTML 中的可滚动内容在 Android 模拟器或手机中无法滚动

我有一个显示一些 HTML 内容的 WebView。在我的 HTML 中,我为特定的 div 放置了“overflow-y:scroll”。现在,当项目数量超过 div 的面积时,div 不会滚动...

回答 2 投票 0

网格布局在真实手机 Android 中不显示

我正在 GridLayout 中制作卡片视图。我在真实设备上运行我的应用程序。我的 CardView 未显示 我也在 StackOverflow 中检查了类似的问题,但该问题可能与我的代码有所不同 那个...

回答 2 投票 0

BottomNavigationView 覆盖片段

在Android Studio中创建新应用程序时,使用底部导航活动,我发现片段底部的内容不会显示,因为BottomNavigationView是h...

回答 3 投票 0

如何使用recyclerview将图库中的所有图像获取到我的应用程序?以及如何在onbind支架中设置图像以加载图库图像

public void onBindViewHolder(MyAdapter.MyViewHoldeholder,int位置){ //如何设置图像以加载图库图像 ---------- } //以及如何从galle获取图像的代码...

回答 5 投票 0

如何以编程方式获取颜色属性的值

当我使用resolveAttribute()找出?attr/colorControlNormal的颜色值时,我得到236: TypedValue typedValue = new TypedValue(); getTheme().resolveAttribute(R.attr.colorControlNormal,

回答 4 投票 0

Android TextView 多行

我想要一个应该分成 4 行的 TextView。例如 维沙尔·维亚斯 拥有 第342章 名声 注意,重心应该是center_horizontal 我尝试了以下操作: 我想要一个应该分成 4 行的 TextView。例如 Vishal Vyas Having 342 Reputation 注意,重力应该是center_horizontal 我尝试了以下方法: <TextView android:gravity="center_horizontal" android:id="@+id/lblUserRep" android:layout_width="70dp" android:layout_height="wrap_content" android:lines="4" android:maxLines="4" android:text="VishalVyas Having 342 Reputation" > </TextView> 这有效!但会产生以下输出: VishalVyas Having 342 Reputation 问题: 它不适用于单词 Vishal 和 Vyas 之间的空格。 android:layout_width="70dp" 已被编码,可以是任何具有 n 个字符的名称,而不是 VishalVyas。 请指教。 补充: 如果我需要编写一个自定义的 TextView 来实现这一点,那就太好了,但我需要一些指导。 提前致谢。 我认为它正在包装,因为“Vishal Vyas”超过了 70dp。相反,在宽度上执行 wrap_content 并使用换行符代替换行符(即“Vishal Vyas 第342章 声誉”) 您应该能够插入换行符 \n 来控制分割的位置。完成此操作后,您可以将 TextView 扩展得更宽,以便它可以容纳更长的用户名,但仍然在正确的位置中断。 android:lines="2" android:minLines="2" android:singleLine="false" 即使 Android Studio 警告 android:singleLine=false 已弃用,也请保留它,并且可以根据文本的长度为文本框设置所需的行数 我这样做了: TextView的容器: android:layout_width="match_parent" android:layout_height="match_parent" 文本视图: android:layout_width="match_parent" android:layout_height="wrap_content" 那么, TextView 的文本显示为两行或更多... 我有不同的问题,但当我展示你的解决方案时,我的问题也解决了! 谢谢你的解决方案

回答 5 投票 0

ListView setOnItemClickListener 在自定义列表视图中不起作用

我有一个列表视图,每行有两个文本视图和一个编辑文本,列表视图 setOnItemClickListener() 不起作用。 这是我的 Java 代码。 公共类 CreateChallan 扩展 Activity { 列表视图

回答 5 投票 0

Android 仅当先前输入为“是”时才会要求下一个输入

我正在通过本机android实现数据请求表单,用户应该在其中输入各种字段。考虑以下场景: 其中一个字段询问保险?,它寻求是/否输入...

回答 2 投票 0

Jetpack Compose 中的动画重组(视图更改)

有没有一种方法可以在 Jetpack Compose @Composable 中自动动画组合变化?例如,如果在重组中删除了先前显示的小部件,淡出动画是否可以

回答 3 投票 0

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