小编Bru*_*uno的帖子

Android 中带标题的边框

我想在 Android 中创建一个组件。该组件应该是一个标题类似于 的边框,TextInputLayout并且可以在内部包含任何布局。

文本输入布局

我在这里找到了一个解决方案,但我想知道是否有人可以分享不同的解决方案。我认为那是很hacky的。

该布局包括两种线性布局,第一个是带有标题的顶部边框线,第二个是带有左、右、下边框的内容。

你怎么认为?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="20dp">
        <LinearLayout
            android:id="@+id/main"
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:orientation="horizontal"
            android:gravity="center_vertical"
            android:weightSum="2">
            <View
                android:layout_width="fill_parent"
                android:layout_height="2dp"
                android:layout_weight="1"
                android:background="#2ebadc"/>
            <TextView
                android:gravity="bottom"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:text="Hello World" />
            <View
                android:layout_width="wrap_content"
                android:layout_height="2dp"
                android:layout_marginRight="5dp"
                android:background="#2ebadc"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginTop="10dp"
            android:padding="10dp"
            android:background="@drawable/topless_border">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="This is a border with title"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="The top inset of the border is set to -3 to …
Run Code Online (Sandbox Code Playgroud)

user-interface android kotlin material-design android-textinputlayout

5
推荐指数
1
解决办法
1308
查看次数

AsyncTask加载图像RecyclerView

我正在尝试创建类似于该应用程序的应用程序: 一个在recyclerview中具有一些图像和描述(卡片视图)的应用程序

首先,我从图像的数据库标题,描述和图像的URL加载CardView的所有信息。当我将所有信息放到RecyclerView中时,(标题和描述)可以正确显示,但是对于图像,我创建了一个AsyncTask类来从URL加载图像,从而使用户不必等待太多时间来等待应用程序响应。

如果用户缓慢滚动,图像加载正确并且一切都很好,但是如果我快速滚动,则会遇到一些问题,例如,项目3中显示的图像显示在最后一个项目中,直到最后一个项目为止图像已加载并刷新。

这是我的适配器在其中加载图像的一些代码:

@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
    if (holder instanceof EventosViewHolder) {
        ......
        //Load the image (getFoto() get drawable)
        if (eventoInfoAux.getFoto()==null){
            CargarImagen cargarImagen = new CargarImagen(((EventosViewHolder) holder).vRelativeLayout,eventoInfo,position);
            cargarImagen.execute();
        }else{
            ((EventosViewHolder) holder).vRelativeLayout.setBackground(eventoInfoAux.getFoto());
        }   
    }
}
Run Code Online (Sandbox Code Playgroud)

这里是CargarImagen类的代码:

//Clase para cargar imagenes con una tarea asíncrona desde un url de la imagen
public class CargarImagen extends AsyncTask<String, String, Boolean>{

//RelativeLayout donde se introduce la imagen de fondo
RelativeLayout relativeLayout=null;
//EventoInfo para obtener la url de la …
Run Code Online (Sandbox Code Playgroud)

android image android-asynctask android-cardview android-recyclerview

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