android-layout 相关问题

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

Android 键盘隐藏 EditText

当我尝试在屏幕底部的 EditText 中写入内容时,软键盘会隐藏 EditText。我该如何解决这个问题?下面是我的 xml 代码。我在 Frag 中使用这个...

回答 12 投票 0

setVisibility(View.INVISIBLE);有什么区别设置可见性(0);

当我将文本视图可见性设置为 文本.setVisibility(0);我无法隐藏这个文本视图。但是当我将代码更新为text.setVisibility(View.INVISIBLE)后,textview被隐藏了......

回答 6 投票 0

防止 Snackbar 与 Activity 子 Fragment 的 ConstraintLayout 中的 FloatingActionButton 重叠

这是我当前的设置: 我有一个在根布局(CoordinatorLayout)上注册小吃栏的 BaseActivity: 这是我当前的设置: 我有一个在根布局(CoordinatorLayout)上注册小吃栏的 BaseActivity: <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/snackbar_container" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_dodgeInsetEdges="bottom"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content"> <include layout="@layout/toolbar" /> </com.google.android.material.appbar.AppBarLayout> <include layout="@layout/progressbar_with_text" /> <androidx.fragment.app.FragmentContainerView android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout> 现在我添加一个如下所示的片段: <?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"> <androidx.viewpager.widget.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="0dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toTopOf="parent" /> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/fab_save" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/content_save" android:tint="@android:color/white" android:visibility="gone" app:backgroundTint="@color/secondary" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:tint="@android:color/white" app:useCompatPadding="true" tools:ignore="SpeakableTextPresentCheck" tools:visibility="visible" /> </androidx.constraintlayout.widget.ConstraintLayout> 我希望晶圆厂在显示时被小吃栏推起,目前它与小吃栏重叠。 我知道使用 CoordinatorLayout 作为根并将 FloatingActionButton (FAB) 放置在其中可以与属性 app:layout_dodgeInsetEdges="bottom" 配合使用。此设置可确保在显示 Snackbar 时将 FAB 向上推。但是,对于子片段,我无法获得类似的结果。是的,我的设置必须保持原样,因为我有多个彼此不同的片段,并且包含独特样式的 FAB,因此将 FAB 移动到活动级别不是一个选项。 您应该在 BaseActivity 中创建一个方法来显示小吃栏,在该方法中通过其 id 找到 coordinatorLayout。 public void showSnackbar(String message, int duration) { CoordinatorLayout coordinatorLayout = findViewById(R.id.snackbar_container); Snackbar.make(coordinatorLayout, message, duration).show(); } 你的fragment应该能够访问BaseActivity。确保你的activity实现了某个接口,这将允许fragment与activity进行通信。 public class MyFragment extends Fragment { private BaseActivity activity; @Override public void onAttach(Context context) { super.onAttach(context); if (context instanceof BaseActivity) { activity = (BaseActivity) context; } } private void showSnackbar(String message) { activity.showSnackbar(message, Snackbar.LENGTH_SHORT); } }

回答 1 投票 0

如何防止RecyclerView覆盖其下方的视图?

这是我的布局: 这是我的布局: <androidx.appcompat.widget.LinearLayoutCompat 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="wrap_content" android:orientation="vertical" tools:context=".ScannerFragment"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <androidx.camera.view.PreviewView android:id="@+id/cameraPreview" android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintDimensionRatio="16:9" app:layout_constraintTop_toTopOf="parent" /> <ScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constraintTop_toBottomOf="@id/cameraPreview"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/saleList" android:layout_width="match_parent" android:layout_height="wrap_content" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" /> </ScrollView> <View android:id="@+id/filler" android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintTop_toBottomOf="@id/scrollView" app:layout_constraintVertical_weight="1" /> <androidx.appcompat.widget.LinearLayoutCompat android:id="@+id/total_widget" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="4dp" app:layout_constraintBottom_toBottomOf="parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/total" android:textSize="24sp" /> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" /> <TextView android:id="@+id/sum" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="24sp" /> </androidx.appcompat.widget.LinearLayoutCompat> </androidx.constraintlayout.widget.ConstraintLayout> </androidx.appcompat.widget.LinearLayoutCompat> 这就是它的样子: 请查看图像底部,RecyclerView 中的项目是否覆盖了“Total”文本。我希望 RecyclerView 最多扩展至“Total”文本的顶部。 问题是,即使 RecyclerView 为空,我也希望“Total”文本粘在广告上方的底部。因此我不能简单地以这种方式限制它。 我尝试了“填充”视图的各种约束,但这也无法正常工作。在某些情况下,添加到 RecyclerView 的项目会使 RecyclerView 从 CameraPreview 和“Total”文本之间的中间展开。只是最终覆盖了 CameraPreview 和“Total”文本... 是否有一种有意识的方法来实现我想要的布局,而无需无休止地摆弄它? 几件事: 1)Recyclerviews 内置了滚动功能。无需将其放入 ScrollView 中。 2)向RecyclerView添加constraint_bottom_toTopOf(在删除滚动视图之后)并将其限制在您不希望它重叠的任何视图之上(我假设是total_widget)

回答 1 投票 0

我的拖放功能在 Android Studio 中不起作用

如上图所示,当您拖动某些内容时,有对齐选项“to RightOf=button”、“below=button”,但是当我拖动某些内容时,不会显示类似的内容。谁能帮我解决...

回答 5 投票 0

如何立即用第二个 Toast 替换当前的 Toast,而不等待当前的 Toast 完成? [重复]

我有很多按钮。单击每个按钮时,我会显示一个 Toast。但是,当 Toast 加载并显示在视图中时,单击另一个按钮,直到正在显示的 Toast 才显示 Toast...

回答 1 投票 0

是否有一个CSS属性,其作用类似于android XML“包装内容”?

特别是我有一个 GWT 项目,其中包含 我想要符合设定的宽度并根据需要扩展到底部的 TextArea 元素。 我想要符合集合宽度的 ListBox 元素...

回答 3 投票 0

我们可以在Android表单中为Android组件使用CSS吗?

无论如何都可以使用css来实现android控件,我们可以为类似的控件创建类吗? 谢谢 阿提夫

回答 4 投票 0

HelpStack:预定义颜色不起作用

我尝试将HelpStack与我的系统集成,但每次我尝试添加它时,我都会收到有关预定义颜色的编译错误,我想知道为什么预定义的android颜色不能与此一起使用

回答 1 投票 0

ConstraintLayout 损坏了吗?

这是我的活动布局: 这是我的活动布局: <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"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar" app:layout_constraintTop_toTopOf="parent" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> <com.google.android.material.appbar.MaterialToolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" /> </com.google.android.material.appbar.AppBarLayout> <androidx.fragment.app.FragmentContainerView android:id="@+id/nav_host_fragment" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="wrap_content" app:defaultNavHost="true" app:layout_constraintBottom_toTopOf="@id/adView" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@id/appbar" app:navGraph="@navigation/nav_graph" /> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="match_parent" android:layout_height="wrap_content" app:adUnitId="ca-app-pub-3940256099942544/9214589741" app:adSize="BANNER" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> 这是里面显示的一个Fragment: <androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" tools:context=".ScannerFragment"> <androidx.camera.view.PreviewView android:id="@+id/cameraPreview" android:layout_width="match_parent" android:layout_height="200dp"/> <androidx.recyclerview.widget.RecyclerView android:id="@+id/sale_list" android:layout_width="match_parent" android:layout_height="wrap_content"/> <View android:layout_width="match_parent" android:layout_height="0sp" android:layout_weight="1"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Total" android:textSize="24sp"/> </androidx.appcompat.widget.LinearLayoutCompat> 这就是它的样子: 看一下FragmentContainerView:位于应用栏下方和广告视图上方是有限制的。然而,该片段显然违反了这些约束并忽略了应用栏和 adView。 我做错了什么吗?或者ConstraintLayout只是坏了?如何实现我想要的布局? 我已经尝试将 FragmentContainerView 放入 LinearLayout 以及 LinearLayout 上的约束,但无法见证任何变化。 您的 FragmentContainer 的高度为 wrap_content,这意味着它不会遵守 constraintTop_toBottomOf(和类似)属性设置的约束。 使用0dp(MATCH_CONSTRAINT)作为其高度是关键。请阅读更多相关信息这里。 ...前两个的工作方式与其他布局类似。最后一个将以匹配设置的约束的方式调整小部件的大小。如果设置了边距,它们将被考虑到计算中。 <androidx.fragment.app.FragmentContainerView android:id="@+id/nav_host_fragment" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="0dp" app:defaultNavHost="true" app:layout_constraintBottom_toTopOf="@id/adView" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@id/appbar" app:navGraph="@navigation/nav_graph" />

回答 1 投票 0

如何去除列表视图中的边框?

在Android上,如何删除列表底部列表视图中出现的线条?

回答 6 投票 0

错误:找不到符号View root = inflater.inflate(R.layout.toolbar,parent,false);

我使用数据绑定来连接UI,但是当我重建项目时,出现以下错误: 错误:找不到符号 View root = inflater.inflate(R.layout.toolbar, Parent, false); ...

回答 1 投票 0

C# Xamarin Android |从课堂更改内容视图

我正在添加按钮和类中的单击事件,当您单击按钮时,您需要转到不同的内容视图并带上一个变量。 受保护的覆盖无效 OnPostExec...

回答 1 投票 0

在 Android Studio 中哪里可以找到 styles.xml 文件?

我有一个非常简单的应用程序,它运行一个 html 文件。我真的很想改变状态栏的颜色,因为黑色的标准顶部和底部对于 p 的调色板来说太糟糕了......

回答 4 投票 0

Android 中微调器的自定义布局

我正在开发一个Android应用程序,我必须为微调项目实现自定义布局。 我会实现这样的旋转器: 我有一个问题来实现“金箭头和边框&qu...

回答 2 投票 0

android studio 中的布局指南

我是 android studio 和 android 开发的新手。我正在尝试使用指南来使我的布局适应所有屏幕尺寸。我正在按百分比标签设置指导方针。 例如:在我的 l...

回答 1 投票 0

如何使用 TextView 在 android 中设置动态文本样式

我正在使用 XML 设计来显示以以下格式动态创建的文本 细节 1.电子序列号:0-4638929 2. 硬件地址:E4:EE:D8:25:44:A3 3.硬件版本:1 4. 制造...

回答 1 投票 0

应用程序已发布在 Play 商店上,但未显示在平板电脑上

我已经在 Google Play 商店上发布了一个应用程序,但是当我尝试在平板电脑上下载它时,它说应用程序不兼容。 另外,在开发人员控制台中,我收到以下消息:您的布局应该利用...

回答 1 投票 0

滑动时从一种布局到另一种布局的透明扩展圆过渡动画

当用户按住屏幕时,手指应该变得透明,以便他们可以看到底层布局。当他们继续按住手指并滑动时,我想创建一个

回答 1 投票 0

如何在 Android Activity 中使可滚动布局后面跟着另一个布局(第二部分)

这是如何在 Android Activity 中使可滚动布局后面跟着另一个布局的延续 我使用了 Finn Marquardt 提出的解决方案。 与预期相比

回答 1 投票 0

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