小编Che*_*amp的帖子

Android ConstraintLayout - 将一个视图放在另一个视图的顶部

我想添加ProgressBar上的顶部Button(均为内ConstraintLayout).

<Button
    android:id="@+id/sign_in_button"
    android:layout_width="280dp"
    android:layout_height="75dp"
    android:layout_marginBottom="75dp"
    android:layout_marginTop="50dp"
    android:text="@string/sign_in"
    android:textColor="@color/white"
    android:textSize="22sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/passwordEditText"
    app:layout_constraintVertical_bias="0.0"/>

<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="@+id/sign_in_button"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="@+id/sign_in_button"
    android:layout_marginBottom="8dp"
    app:layout_constraintVertical_bias="0.5"
    android:layout_marginLeft="8dp"
    app:layout_constraintLeft_toLeftOf="@+id/sign_in_button"
    android:layout_marginRight="8dp"
    app:layout_constraintRight_toRightOf="@+id/sign_in_button"/>
Run Code Online (Sandbox Code Playgroud)

但即使在呼吁bringToFront进入ProgressBaronCreate,它总是留在后面Button.

ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar);
progressBar.bringToFront();
Run Code Online (Sandbox Code Playgroud)

android android-layout android-constraintlayout

85
推荐指数
5
解决办法
4万
查看次数

在ConstraintLayout中以编程方式删除/添加约束

我想根据某些条件以编程方式删除和添加约束.以下是截图:

我想删除它,但在代码中:

这是在顶部删除约束的按钮

所以想要以编程方式实现同​​样的效果

这是我试过的代码:

    if (advertisements.size() > 0) { //my own condition
        ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) btnCreateAd.getLayoutParams();
        layoutParams.topToBottom = R.id.imvEmpty; //the imageview that is in center of the view
        btnCreateAd.setLayoutParams(layoutParams);
        recyclerView.setVisibility(View.VISIBLE);
        txvMyAdEmptyText.setVisibility(View.GONE);
        imvEmpty.setVisibility(View.GONE);
        adapter.setList(advertisements);
        adapter.notifyDataSetChanged();
    } else {
        ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) btnCreateAd.getLayoutParams();
        layoutParams.topToBottom = -1; //here i am trying to remove top constraint but it doesn't work
        btnCreateAd.setLayoutParams(layoutParams);

        recyclerView.setVisibility(View.GONE);
        txvMyAdEmptyText.setVisibility(View.VISIBLE);
        imvEmpty.setVisibility(View.VISIBLE);
        adapter.setList(new ArrayList<Advertisement>());
    }
    mConstraintView.invalidate(); //this is my constraint view
Run Code Online (Sandbox Code Playgroud)

编辑

我也尝试过使用 ConstraintSet,但结果甚至不同,我的RecyclerView(设置为父视图的边界)正在消失

 ConstraintSet set = new …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-layoutparams android-constraintlayout

31
推荐指数
3
解决办法
2万
查看次数

Android浏览器会从完整限定符中删除https://方案

在我的应用程序中,我在CustomTabsIntent或WebView中显示外部HTML站点:

if (customTabsIntent != null) customTabsIntent.launchUrl(this, Uri.parse("http://some.where.com/site.html"));
else startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://some.where.com/site.html")));
Run Code Online (Sandbox Code Playgroud)

但该HTML的风格已经更新,但我的智能手机显示旧样式(旧字体等).

在*.html文件中有一个*.css引用:

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href='https://my.site.com/assets/css/style.css' rel='stylesheet' type='text/css'>
</head>
Run Code Online (Sandbox Code Playgroud)

在那个*.css文件中,引用了一个单独的字体; 例如:

@font-face {
    font-family: 'MyFontRegular';
    src: url('https://www.openfont.org/assets/mail/fonts/MyFontWeb-Regular.woff') format('woff'), 
    url('https://www.openfont.org/assets/mail/fonts/MyFontWeb-Regular.eot') format('embedded-opentype');
}
Run Code Online (Sandbox Code Playgroud)

正如我所说,智能手机中的Chrome浏览器不显示引用的字体,因为它会关闭http://https://.当我手动将该方案添加到地址栏中时,将显示正确的样式.

当我的Android应用程序调用它时,如何在我的android浏览器的地址字段中强制https://方案?

android webview android-webview chrome-custom-tabs android-customtabs

15
推荐指数
1
解决办法
346
查看次数

RecyclerView快速滚动拇指高度太小,不适合大型数据集

我正在使用默认的RecyclerView快速滚动,我按照本指南来支持它.

现在,问题是拇指根据数据集的大小调整其高度.对于100以上的大件物品,拇指变得非常小,几乎难以对拖动作出反应.

请问有什么方法可以为快速滚动拇指设置最小高度.

android android-recyclerview

15
推荐指数
2
解决办法
3105
查看次数

Android ConstraintLayout TextView离开屏幕

如图所示,文字不在墙上.这是一个奇怪的行为,我认为这是一个错误

这是一个屏幕截图:

在此输入图像描述

这是标题xml:

<android.support.constraint.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="wrap_content"
    android:background="?android:attr/windowBackground"
    android:orientation="vertical">

    <TextView
        android:id="@+id/street_name"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginStart="15dp"
        android:text="street name"
        android:textColor="?AppTheme.InformationText"
        android:textSize="14sp"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_marginTop="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="19dp"
        android:layout_marginLeft="0dp"
        app:layout_constraintWidth_default="wrap"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="@+id/guideline29"
        app:layout_constraintTop_toTopOf="@+id/guideline37"
        app:layout_constraintRight_toLeftOf="@+id/guideline30"
        app:layout_constraintHorizontal_bias="0.605"
        app:layout_constraintVertical_bias="0.0"/>

    <ImageView
        android:id="@+id/street_view_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:padding="6dp"
        android:scaleType="fitCenter"
        tools:layout_constraintLeft_creator="1"
        android:layout_marginLeft="0dp"
        app:layout_constraintLeft_toLeftOf="@+id/country_flag_image"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="0dp"
        app:layout_constraintRight_toLeftOf="@+id/guideline29"
        android:layout_marginRight="8dp"
        app:layout_constraintTop_toTopOf="@+id/guideline37"
        android:layout_marginTop="8dp"/>

    <ImageView
        android:id="@+id/country_flag_image"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginLeft="4dp"
        android:layout_marginStart="4dp"
        android:layout_marginTop="8dp"
        android:adjustViewBounds="true"
        android:paddingBottom="5dp"
        android:paddingLeft="5dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintTop_creator="1"
        />

    <de.hdodenhof.circleimageview.CircleImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/exit_image"
        android:layout_width="46dp"
        android:layout_height="46dp"
        android:layout_marginBottom="8dp"
        android:layout_marginRight="-4dp"
        android:src="@drawable/exit_custom"
        app:border_color="#FF000000"
        app:layout_constraintBottom_toBottomOf="@+id/street_view_image"
        app:layout_constraintRight_toRightOf="@+id/street_view_image"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintRight_creator="1"
        />

    <android.support.constraint.Guideline
        android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android textview android-constraintlayout

12
推荐指数
2
解决办法
9763
查看次数

在API级别28上找不到画布变量

下面Canvas没有在android 28中找到的变量.

canvas.saveLayer(0, 0, getWidth(), getHeight(), null,
                Canvas.MATRIX_SAVE_FLAG |
                        Canvas.CLIP_SAVE_FLAG |
                        Canvas.HAS_ALPHA_LAYER_SAVE_FLAG |
                        Canvas.FULL_COLOR_LAYER_SAVE_FLAG |
                        Canvas.CLIP_TO_LAYER_SAVE_FLAG);
Run Code Online (Sandbox Code Playgroud)

android canvas android-9.0-pie

11
推荐指数
1
解决办法
6388
查看次数

如何在ConstraintLayout 1.1.0(测试版)中使用链中的边距

自从转换到ConstraintLayout版本1.1.0-beta4后,我的几个布局都爆炸了.在进行任何更改之前,我希望更好地了解利润率如何在ConstraintLayout链条中发挥作用.在下文中,我将ConstraintLayout版本1.0.2中的布局与版本1.1.0-beta4进行比较,但我认为该问题首先出现在1.1.0-beta2中.

我的目标是让一些文本视图在屏幕上伸展,第一和第二文本视图之间以及第二和第三文本视图之间存在间隙.背景应显示在这些边距中.为此,我创建一个水平链并指定从左侧文本视图到中心文本视图的结束边距以及从中心文本视图到右侧文本视图的结束边距.横向链式是spread_inside.

示例1 - 使用ConstraintLayout 1.0.2版

这就是版本1.0.2中的内容,并且是我所期望的.

在此输入图像描述

<android.support.constraint.ConstraintLayout 
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@android:color/holo_blue_light">

    <TextView
        android:id="@+id/tvLeft"
        android:layout_width="0dp"
        android:layout_height="35dp"
        android:layout_marginEnd="8dp"
        android:background="@android:color/white"
        android:gravity="center"
        android:text="Text1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/tvCenter"
        app:layout_constraintHorizontal_chainStyle="spread_inside"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="HardcodedText" />

    <TextView
        android:id="@+id/tvCenter"
        android:layout_width="0dp"
        android:layout_height="35dp"
        android:layout_marginEnd="8dp"
        android:background="@android:color/white"
        android:gravity="center"
        android:text="Text2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/tvRight"
        app:layout_constraintStart_toEndOf="@+id/tvLeft"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="HardcodedText" />

    <TextView
        android:id="@+id/tvRight"
        android:layout_width="0dp"
        android:layout_height="35dp"
        android:background="@android:color/white"
        android:gravity="center"
        android:text="Text3"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/tvCenter"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="HardcodedText" />

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

示例2 - 使用ConstraintLayout版本1.1.0-beta4

这个相同的布局在版本1.1.0-beta4中如下所示ConstraintLayout.请注意,边距已消失.我希望这看起来与示例1相同,但事实并非如此.

在此输入图像描述

示例3 - 使用带有起始边距的ConstraintLayout版本1.1.0-beta4

如果我采用相同的布局并简单地8dp向右侧文本视图添加一个开始边距(tvRight),我的边距不仅会重新出现在中间和右侧文本视图之间,还会出现在左侧和中间文本视图之间,尽管我没有更改边距.

[图片]

这不仅仅是之前设定的利润突然被尊重.如果我将最右边文本视图的起始边距设置为"48dp",48dp则左侧和中心文本视图之间也会显示边距.

在此输入图像描述

<android.support.constraint.ConstraintLayout 
    android:layout_width="match_parent"
    android:layout_height="50dp" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-constraintlayout

10
推荐指数
2
解决办法
5750
查看次数

带导航组件的单个活动:如何处理不同的AppBar /主题

自Google I/O宣布之后不久,我一直在使用新的导航组件,并且也开始尽可能地接受单项活动.

单一活动允许我在视图之间共享ViewModel以获得非常棒的体验,如果我没有被迫,我真的不想回到多活动.

但是有一些东西阻碍了:AppBar/Themes(状态栏)到单一活动的概念.

这是我正在进行的设计的一部分:

AppBar设计在不同的部分

正如您所看到的,Actionbar /状态栏的外观有不同的要求.

  1. 这是一个带有标准动作栏的简单抽屉
  2. 图像在半透明状态栏下的经典细节,CollapsingToolbarLayout在向上滚动时应该用于变成标准动作栏
  3. 在这种情况下,它是非标准的操作栏,我称之为"浮动工具栏",因为它没有扩展到屏幕的全部,并包含已经扩展的SearchView/EditText
  4. 带标签的相当标准的AppBar

离开单项活动所产生的问题清单:

  • 不能ViewModel在活动之间分享
  • 重复使用已在另一个活动导航图中定义的部分的复杂导航必须复制/移动到专用活动中
  • 返回导航"重建"在活动之间不起作用

如果可能的话,这些是我想要避免的问题,但是你们如何在导航组件的单一活动中管理这些情况.任何的想法?

android-layout android-fragments android-architecture-navigation

9
推荐指数
1
解决办法
226
查看次数

在没有Google Play服务合并的情况下为oAuth Google使用webview的替代方案

我们的自定义设备可在Android操作系统上运行,但未包含Google Play服务.
我们使用Webview Oauth2.0身份验证进行Google登录.根据文件,它已被删除.
我读到有一种方式https://developers.google.com/identity/sign-in/android/,但这似乎需要gradle合并游戏服务.
那么我可以使用哪种方式进行谷歌身份验证?
我找到了两个选项如下,但它们对我的情况有帮助吗?
1. https://firebase.google.com/docs/auth/android/start/
2. https://developers.google.com/api-client-library/java/google-api-java-client/oauth2

哪个可能是最适合我的要求
请帮助.
此致,
Shraddha

android webview oauth-2.0 google-oauth

8
推荐指数
1
解决办法
3344
查看次数

我可以在Android Studio 3.0中设计自定义尺寸活动吗?

通常,活动将显示最大屏幕.我希望显示一个宽度为400px,高度为500px的窗口,但是下面仍然显示一个完整的窗口,为什么?

主要活动

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}
Run Code Online (Sandbox Code Playgroud)

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="400px"
        android:layout_height="500px"
        tools:context=".MainActivity">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World OK!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

到克柳月

谢谢!但是你的代码不起作用,运行代码后窗口全屏显示.

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val m = windowManager
        val d = m.defaultDisplay
        val p = window.attributes
        p.height = dp2px(this, 500f)
        p.width = dp2px(this, 400f)
        window.attributes = p

    }

    private fun dp2px(context: Context, …
Run Code Online (Sandbox Code Playgroud)

android

8
推荐指数
2
解决办法
274
查看次数