android-layout 相关问题

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

为什么我们不像在 XML 中那样在 Jetpack compose 中使用 ConstraintLayout?

我一直在审查代码,我意识到我们不像在 XML 中那样经常使用 ConstraintLayout。 在 XML 中,由于性能问题,我们被鼓励使用 ConstraintLayout,而不是那些......

回答 1 投票 0

不同屏幕尺寸和分辨率的Android应用程序UI问题

这是我第一次为 Android 开发,我几乎完成了应用程序,但当我开始测试它时,我遇到了一些与 UI 相关的问题。我在使用 Galaxy s6 Edge 对其进行编程时测试了该应用程序...

回答 2 投票 0

无法更改底部导航图标色调

我试图对底部导航实施图标色调,但由于某种原因似乎不起作用, 我添加了硬编码的#color代码,并将其添加到colors.xml中,并为此创建了一个选择器

回答 1 投票 0

LinearLayout 中的 TextView 被另一个 TextView 推到外面

美好的一天!我正在尝试实现一种特定的布局。我希望有人能给我一个关于如何正确做这件事的提示。 所以,在我的布局中,我在 LinearLayout 中有两个带有

回答 5 投票 0

在TableLayout中不工作时查看wrap_content

我将带有单元格的表格行动态添加到表格中。 行和单元格已添加,但单元格中的文本不会换行。 部分代码如下: 布局如下: 我将带有单元格的表格行动态添加到表格中。 行和单元格已添加,但单元格中的文本不会换行。 部分代码如下: 布局如下: <TableLayout android:id="@+id/TableTheOpenQuestion" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="12dp" android:layout_marginTop="1dp" android:layout_marginRight="12dp" android:backgroundTint="@color/backgroundColor" android:visibility="gone" android:stretchColumns="*"> </TableLayout> 而我使用上述布局对应的Java文件如下: tableLayout = findViewById(R.id.TableTheOpenQuestion); TableRow tr = new TableRow(dContext); TableRow.LayoutParams params = new TableRow.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT, 1); params.setMargins(12, 0, 12, 0); tr.setLayoutParams(params); TableRow.LayoutParams cellParams = new TableRow.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT); TextView tv = new TextView(dContext); tv.setLayoutParams(cellParams); tv.setPadding(5, 10, 10, 10); tv.setText("A very long text.A very long text.A very long text.A very long text.A very long text.A very long text.A very long text.A very long text."); tr.addView(tv); // // Add the row to the table // tableLayout.addView(tr); 我一直在搜索很多类似的问题,但似乎没有什么对我有用。非常感谢所有帮助! 对于TextView,TableRow参数应该如下,而不是你写的 TableRow.LayoutParams params = new TableRow.LayoutParams( 0, // Width 0 to allow wrapping TableRow.LayoutParams.WRAP_CONTENT, // Wrap content height 1.0f // Equal weight for each cell ); 然后您可以将 params 分配给您的 TextView TextView textView = new TextView(context); textView.setText(text); textView.setLayoutParams(params);

回答 1 投票 0

在TableLayout中不工作时查看wrap_content

我将带有单元格的表格行动态添加到表格中。 行和单元格已添加,但单元格中的文本不会换行。 部分代码如下: 布局如下: 我将带有单元格的表格行动态添加到表格中。 行和单元格已添加,但单元格中的文本不会换行。 部分代码如下: 布局如下: <TableLayout android:id="@+id/TableTheOpenQuestion" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="12dp" android:layout_marginTop="1dp" android:layout_marginRight="12dp" android:backgroundTint="@color/backgroundColor" android:visibility="gone" android:stretchColumns="*"> </TableLayout> 而我使用上述布局对应的Java文件如下: tableLayout = findViewById(R.id.TableTheOpenQuestion); TableRow tr = new TableRow(dContext); TableRow.LayoutParams params = new TableRow.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT, 1); params.setMargins(12, 0, 12, 0); tr.setLayoutParams(params); TableRow.LayoutParams cellParams = new TableRow.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT); TextView tv = new TextView(dContext); tv.setLayoutParams(cellParams); tv.setPadding(5, 10, 10, 10); tv.setText("A very long text.A very long text.A very long text.A very long text.A very long text.A very long text.A very long text.A very long text."); tr.addView(tv); // // Add the row to the table // tableLayout.addView(tr); 我一直在搜索很多类似的问题,但似乎没有什么对我有用。非常感谢所有帮助! 对于TextView,TableRow参数应该如下,而不是你写的 TableRow.LayoutParams params = new TableRow.LayoutParams( 0, // Width 0 to allow wrapping TableRow.LayoutParams.WRAP_CONTENT, // Wrap content height 1.0f // Equal weight for each cell ); 然后您可以将 params 分配给您的 TextView TextView textView = new TextView(context); textView.setText(text); textView.setLayoutParams(params);

回答 1 投票 0

如何正确地将背景或大图片添加到Android Studio for Views?

例如,我想将 .jpg 4k 图像设置为背景,或者我想将其他分辨率 .jpg/.png 添加到屏幕上的某个位置(例如从视图中消失的字符)。怎样...

回答 1 投票 0

材质按钮切换组不可见

我正在尝试在现有应用程序中使用材质切换组。 我发现它仅在应用程序使用 Material 组件主题时才有效(可见)。 由于现有的应用程序是...

回答 2 投票 0

Listview 为最后一项上的每个项目添加填充

列表视图包含团队,团队包含玩家。 我有一个由回收适配器填充的列表视图,但我无法找到它底部最后一个填充的位置? 永远...

回答 2 投票 0

ViewPager 在 Coordinator 布局中的高度超出了可用范围

我有一个CoordinatorLayout,在AppBarLayout 中有一个Toolbar 和一个TabLayout。此外,我在 CoordinatorLayout 内部但在 ViewPager 外部有一个 ViewPager。 问题是

回答 5 投票 0

Android:如何从 HorizontalScrollView 中删除空白

如何删除右边的空白? 当我有 5 张或更多照片时,空白就会消失。 有了两张照片,我就得到了空白。 在 Galaxy Nexus 模拟器和我的三星上尝试过......

回答 1 投票 0

在android studio中绘制部分圆作为进度条

总结: 使用图1作为参考。 我需要将灰色部分保留在绿色部分下方,以便当绿色减少时,灰色变得可见。但我也想要未覆盖的部分(只是灰色而不是......

回答 5 投票 0

在 Jetpack Compose 中打开键盘时布局不会向上移动

我在 Jetpack Compose 中有一个布局,其中有几个可组合项(文本视图和输入)需要保留在屏幕顶部,然后还有另一个可组合项(按钮)需要保留在屏幕顶部

回答 1 投票 0

Android Compose 针对特定文本字段的伪造键盘

我有一个屏幕,其中一些文本字段我想显示“假”键盘。键盘应该能够有我喜欢的任意数量的按钮,并按照我想要的方式显示。如下图所示。 我的问题...

回答 2 投票 0

如何在Android中创建带有线性渐变边框的自定义视图?

我正在尝试在 Android 中创建一个自定义视图,该视图具有带圆角的线性渐变边框,类似于这些图像中所示的: 我在 Kot 中编写了以下自定义视图类...

回答 1 投票 0

如何调整图像视图以确保图像填充边界但不会裁剪

假设我有一个图像视图,并且我想显示 600 x 900 的图像。我想确保图像填充图像视图,但它不会裁剪“中心裁剪”或使用“scaleXY”。 ...

回答 1 投票 0

如何在 Jetpack Compose 中使用事务执行此滚动隐藏 fab 按钮

如何在 Jetpack Compose 中使用事务执行此滚动隐藏 fab 按钮 像这样我需要它:

回答 4 投票 0

如何在android中使用Kotlin将布局分成四个相等的部分?

我正在android studio上做一些关于将布局分成四个部分的小练习,尽管我的代码与此处提供的代码类似,但我的代码没有给出预期的结果。 @Composabl...

回答 1 投票 0

二进制 XML 文件行 #2 为尝试动态实现主题而膨胀类 android.widget.RelativeLayout 时出错

我一直在尝试在我的项目中实现动态它们,但由于某种原因它给出了以下错误。这就是我尝试实现它的方式。 首先我定义了一些自定义属性,例如: <

回答 4 投票 0

如果没有空格就断线

如果我在 Android 中添加多个文本视图,它会隐藏,当屏幕完成时我需要中断 作为一个例子,我的代码是这样的 如果我在 android 中添加多个文本视图,它会隐藏,当屏幕完成时我需要中断 作为一个例子,我的代码是这样的 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/layout5" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="last checking text"/> </LinearLayout> 结果似乎是 我需要在屏幕关闭时分解文本 并换到另一行。 这只是我以编程方式执行此操作的示例代码,因此请不要回答添加更多线性布局。 对于灵活的布局,您可以使用FlexboxLayout,您可以从Android开发者博客获取详细信息,对于开源FlexboxLayout依赖项,您可以访问Github。 如果您想以编程方式创建 TextView 并为每个 . 这是代码。首先删除布局中的所有textview。 TextView tv[] = new TextView[subCategory.length]; for (int i = 0; i < subCategory.length; i++) { tv[i] = new TextView(this); tv[i].setText(subCategory[i]); tv[i].setId(i); layout5.addView(tv[i]); tv[i].setOnClickListener(onclicklistener); } 对于听众 OnClickListener onclicklistener = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if(v == tv[0]){ //do whatever you want.... } } }; 如果您想在运行时使用文本视图的数量,您可以尝试使用 GridView as <?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="match_parent" android:layout_height="match_parent" android:numColumns="auto_fit" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:stretchMode="columnWidth" android:gravity="center" /> 还有 Gridview item as TextView <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/text" /> 您可以在 onItemClickListener() 中执行操作 //根据位置或文本视图文本,使用 switch case 或其他方式选择操作。 GridView gridView = (GridView) findViewById(R.id.grid_view); gridView.setAdapter(yourCustomAdapterObject); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //here view is your textview switch (position) { case 0: //action break; case 1://action break; .... } } }); 如果您希望您的textView 出现多行且具有可滚动属性,则无需使用多个textView。 检查以下解决方案: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" <!--`enter code here`--> android:background="#000000" android:orientation="vertical" > <TextView android:id="@+id/textView_id" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#40000000" android:maxLines="100" android:paddingLeft="5dp" android:paddingRight="5dp" android:scrollbarThumbVertical="@android:color/transparent" android:scrollbars="vertical" android:textColor="@color/white" android:textSize="16sp" android:textStyle="bold" /> </LinearLayout> 您的活动中的以下代码: TextView txtView = (TextView) findViewById(R.id.TextView_id); txtView.setText("your text here"); txtView.setMovementMethod(new ScrollingMovementMethod());

回答 4 投票 0

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