相关疑难解决方法(0)

如何在android中创建带圆角的视图

我试图在android中创建一个圆角边的视图.到目前为止我找到的解决方案是定义一个带圆角的形状,并将其用作该视图的背景.

这就是我所做的,定义一个drawable,如下所示

<padding
android:top="2dp"
android:bottom="2dp"/>
<corners android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
Run Code Online (Sandbox Code Playgroud)

现在我用它作为我的布局的背景如下

<LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="10dp"
        android:clipChildren="true"
        android:background="@drawable/rounded_corner">
Run Code Online (Sandbox Code Playgroud)

这很好用,我可以看到视图有圆角.

但我的布局中有许多其他子视图说一个ImageView或一个MapView.当我在上面的布局中放置一个ImageView时,图像的角不会被剪裁/裁剪,而是显示为满.

我已经看到了其他解决方法,使它像这里解释的那样工作.

但有没有一种方法可以为视图设置圆角,并且所有子视图都包含在具有圆角的主视图中?

谢谢.

android android-layout android-view android-shape

74
推荐指数
12
解决办法
9万
查看次数

ImageView圆角

我希望图像有圆角.我实现了这个xml代码并在我的图像视图中使用它.但图像与形状重叠.我正在通过异步任务下载图像.

<?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle" >
 <corners android:radius="20dip" />
</shape>


<ImageView
    android:id="@+id/trVouchersImage"
    android:layout_width="55dp"
    android:layout_height="55dp"
    android:layout_marginLeft="8dp"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:layout_alignParentLeft="true"
    android:background="@drawable/ash_arrow"
 />
Run Code Online (Sandbox Code Playgroud)

java xml android rounded-corners imageview

32
推荐指数
6
解决办法
12万
查看次数

如何在滑行中制作圆形裁剪图像的边框

默认情况下,滑行裁剪的图像没有边框我需要在圆形图像中有边框.

android android-glide

21
推荐指数
4
解决办法
3万
查看次数

如何提高Android Studio应用程序构建的速度?

有没有办法显示我的构建过程是哪一个花费最多的时间,然后尝试解决它?

我正在使用Android Studio.我现在不会把我的项目称为大项目,但我想我需要的依赖项使它变大,构建仍需要40-60秒.(从删除多dex之前的90秒开始)

这是我的2015年中期Macbook Pro的规格:

  • 处理器:2.5 GHz Intel Core i7
  • 内存:16GB 1600 MHz DDR3

我不得不删除部分依赖项,以便能够在不启用多dex支持的情况下构建,这节省了我~20秒,但是我想添加更多依赖项,所以我需要改进构建时间,以便我可以重新启用多个dex并实际使用我想要的依赖项.

我看过一些关于修改Android Studio以加快构建时间的帖子,但这些似乎没有用,我宁愿看看能不能解决问题.

这是我当前的依赖项:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

// MY INTERNAL LIBRARIES
    wearApp project(':wear')
    compile project(':ViewPagerIndicator')
    compile project(':connection-manager')
    compile project(':core-library')
    compile project(':activity-manager')
    compile project(':activity-recorder')

    compile 'com.google.android.gms:play-services-maps:7.5.0'
    compile 'com.google.android.gms:play-services-wearable:7.5.0'
    compile 'com.google.android.gms:play-services-location:7.5.0'

    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.android.support:design:22.2.1'
    compile 'com.android.support:cardview-v7:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.android.support:support-annotations:22.2.1'

    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'joda-time:joda-time:2.7'
    compile 'com.androidplot:androidplot-core:0.6.1'

    compile project(':ParseLoginUI')

    /*Images*/
    compile 'com.squareup.picasso:picasso:2.3.3'
    compile 'com.makeramen:roundedimageview:2.1.0' // https://github.com/vinc3m1/RoundedImageView
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'io.reactivex:rxandroid:1.0.1'

//    apt …
Run Code Online (Sandbox Code Playgroud)

android android-studio

13
推荐指数
2
解决办法
4193
查看次数

在 Glide 中制作方形图像,然后将其四舍五入

我解决了一个典型的图像任务:尝试centerCrop()如何使用 Glide 库对图像进行舍入?,但结果似乎是Glide 圆形图像被裁剪在此处输入图片说明

(非圆形)。

我认为 Glide (v.4) 没有正确裁剪图像。我尝试了许多变体,例如GlideApp.with(photo).load(url).circleCrop().into(photo). 可能更好的是首先从矩形创建一个正方形,然后使其成为圆形。

这是 XML 的一部分:

<?xml version="1.0" encoding="utf-8"?>
<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"
    >

    <ImageView
        android:id="@+id/photo"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginStart="15dp"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="20dp"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:src="@drawable/image_1"
        />

    <TextView
        android:id="@+id/name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="7dp"
        android:layout_marginLeft="7dp"
        android:lineSpacingExtra="1sp"
        android:textColor="@color/black"
        android:textSize="20sp"
        app:layout_constraintEnd_toStartOf="parent"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintStart_toEndOf="@+id/photo"
        app:layout_constraintTop_toTopOf="@+id/photo"
        tools:text="Name"
        />

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

更新

抱歉,源图像有问题。我不认为它是用上下白色填充物平方的(添加了线条):

在此处输入图片说明

另一个例子:

在此处输入图片说明

这是因为在后端,他们缩小了矩形图像,使其成为带有白色边框的正方形

android android-glide

3
推荐指数
1
解决办法
4478
查看次数

创建圆形ImageView的最佳方法是什么?

我知道有很多第三方库可以创建一个CircularImageView,但我知道它们都不是很有效(有些不支持动画/转换,有些会有性能问题).

  1. 我需要创建一个类似于Whatsapp Contacts屏幕的屏幕(带有圆形ImageView和一些文本的列表).
  2. 需要在线列表中加载数据.
  3. 我不想裁剪图像或创建位图副本(像这样 - 如何使ImageView形成圆形?)
  4. 点击圆形图像时需要有触摸反馈(波纹效果)

我可以在没有任何第三方库的情况下实现此目 如果没有,请让我知道最好的方法.

android imageview android-layout

-2
推荐指数
1
解决办法
7366
查看次数