标题背景

时间:2018-03-30 14:03:43

标签: android background android-cardview

我如何在cardview上的这个标题中做这个蓝色背景?

enter image description here

我尝试使用蓝色背景进行线性布局,但这会使得安卓程序设置为SO 19或更糟糕的崩溃应用程序

此cardview是listview项目的模板

  • Cardview:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp">
    
        <ImageView
            android:id="@+id/imagem"
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            app:srcCompat="@drawable/a_receber" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="16dp"
            android:layout_marginLeft="-8dp"
            android:layout_toRightOf="@+id/imagem"
            android:background="@drawable/bordas_cardview_azul"/>
    
        <TextView
            android:id="@+id/lista_personalizada_vencimento"
            android:layout_width="300dp"
            android:textColor="#fff"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toEndOf="@+id/imagem"
            android:layout_toRightOf="@+id/imagem"
            android:text="Titulo"
            android:textSize="11sp"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/lista_personalizada_emissao"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/lista_personalizada_vencimento"
            android:layout_toEndOf="@+id/imagem"
            android:layout_toRightOf="@+id/imagem"
            android:text="telefone1"
            android:textSize="12sp"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/lista_personalizada_nome"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/lista_personalizada_emissao"
            android:layout_toEndOf="@+id/imagem"
            android:layout_toRightOf="@+id/imagem"
            android:text="celular"
            android:textSize="12sp" />
    
        <TextView
            android:id="@+id/lista_personalizada_deve"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/lista_personalizada_nome"
            android:layout_toEndOf="@+id/imagem"
            android:layout_toRightOf="@+id/imagem"
            android:text="renda"
            android:textSize="12sp"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/lista_personalizada_valorini"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/lista_personalizada_deve"
            android:layout_toEndOf="@+id/imagem"
            android:layout_toRightOf="@+id/imagem"
            android:text="limite"
            android:textSize="12sp" />
    
        <TextView
            android:id="@+id/lista_personalizada_status"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/lista_personalizada_valorini"
            android:layout_toEndOf="@+id/imagem"
            android:layout_toRightOf="@+id/imagem"
            android:text="bandeira"
            android:textSize="12sp"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/lista_personalizada_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/lista_personalizada_status"
            android:layout_toEndOf="@+id/imagem"
            android:layout_toRightOf="@+id/imagem"
            android:text="id"
            android:visibility="gone" />
    
    </RelativeLayout>
    

线性布局的drawable / bordas_cardview_azul

 <shape
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle" >

 <solid
    android:color="#1874CD"/>

<corners
    android:topRightRadius="4dp"/>

</shape>

当我尝试使用SO 20或更好的Android启动时,它开始正常,没有问题,但以前的停止工作

logcat with android api 19:

  

流程:insidetechnology.studio.ostdor.forbusiness,PID:1915                                                                                           android.view.InflateException:二进制XML文件行#0:错误类膨胀                                                                                                在android.view.LayoutInflater.createView(LayoutInflater.java:621)                                                                                                 在com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)                                                                                               在android.view.LayoutInflater.onCreateView(LayoutInflater.java:670)                                                                                                在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)                                                                                               在android.view.LayoutInflater.rInflate(LayoutInflater.java:756)                                                                                               在android.view.LayoutInflater.rInflate(LayoutInflater.java:759)                                                                                                在android.view.LayoutInflater.rInflate(LayoutInflater.java:759)                                                                                               在android.view.LayoutInflater.inflate(LayoutInflater.java:492)                                                                                                在android.view.LayoutInflater.inflate(LayoutInflater.java:397)                                                                                               at insidetechnology.studio.ostdor.forbusiness.adapater.AdapterCursosPersonalizado.getView(AdapterCursosPersonalizado.java:40)                                                                                               在android.widget.AbsListView.obtainView(AbsListView.java:2263)                                                                                              在android.widget.ListView.makeAndAddView(ListView.java:1790)                                                                                               在android.widget.ListView.fillDown(ListView.java:691)                                                                                                在android.widget.ListView.fillFromTop(ListView.java:752)                                                                                               在android.widget.ListView.layoutChildren(ListView.java:1630)                                                                                              在android.widget.AbsListView.onLayout(AbsListView.java:2091)                                                                                               在android.view.View.layout(View.java:14817)                                                                                               在android.view.ViewGroup.layout(ViewGroup.java:4631)                                                                                              在android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)                                                                                                在android.view.View.layout(View.java:14817)                                                                                               在android.view.ViewGroup.layout(ViewGroup.java:4631)                                                                                                在android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)                                                                                                在android.widget.FrameLayout.onLayout(FrameLayout.java:388)                                                                                             在android.view.View.layout(View.java:14817)                                                                                               在android.view.ViewGroup.layout(ViewGroup.java:4631)                                                                                             在android.support.v4.view.ViewPager.onLayout(ViewPager.java:1795)                                                                                             在android.view.View.layout(View.java:14817)                                                                                              在android.view.ViewGroup.layout(ViewGroup.java:4631)                                                                                              在android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1167)                                                                                             在android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:852)                                                                                             在android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:871)                                                                                              在android.view.View.layout(View.java:14817)                                                                                             在android.view.ViewGroup.layout(ViewGroup.java:4631)                                                                                             在android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1193)                                                                                              在android.view.View.layout(View.java:14817)                                                                                             在android.view.ViewGroup.layout(ViewGroup.java:4631)                                                                                             在android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)                                                                                             在android.widget.FrameLayout.onLayout(FrameLayout.java:388)                                                                                              在android.view.View.layout(View.java:14817)                                                                                               在android.view.ViewGroup.layout(ViewGroup.java:4631)                                                                                              在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)                                                                                              在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)                                                                                               在android.widget.LinearLayout.onLayout(LinearLayout.java:1434)                                                                                              在android.view.View.layout(View.java:14817)                                                                                              在android.view.ViewGroup.layout(ViewGroup.java:4631)                                                                                              在android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)                                                                                               在android.widget.FrameLayout.onLayout(FrameLayout.java:388)                                                                                              在android.view.View.layout(View.java:14817)                                                                                              在android.view.ViewGroup.layout(ViewGroup.java:4631)                                                                                            在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)                                                                                              在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)                                                                                              在android.widget.LinearLayout.onLayout(LinearLayout.java:1434)                                                                                              在android.view.View.layout(View.java:14817)                                                                                              在android.view.ViewGroup.layout(ViewGroup.java:4631)                                                                                              在android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)                                                                                          在android.widget.FrameLayout.onLayout(FrameLayout.java:388)                                                                                             在android.view.View.layout(View.java:14817)                                                                                              在android.view.ViewGroup.layout(ViewGroup.java:4631)                                                                                              在android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1987)                                                                                              在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1744)                                                                                                在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)                                                                                             在android。

适配器列表视图

  public class AdapterContasPersonalizado extends BaseAdapter {

private final List<Curso2> cursos;
private final contas act;

public AdapterContasPersonalizado(List<Curso2> cursos, contas act) {
    this.cursos = cursos;
    this.act = act;
}

@Override
public int getCount() {
    return cursos.size();
}

@Override
public Object getItem(int position) {
    return cursos.get(position);
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
 //line 40 below
    View view = act.getLayoutInflater().inflate(R.layout.lista_contas_personalizada, parent, false);

    Curso2 curso = cursos.get(position);

    ImageView imagem = (ImageView)
            view.findViewById(R.id.imagem);
    TextView vencimento = (TextView)
            view.findViewById(R.id.lista_personalizada_vencimento);
    TextView emissao = (TextView)
            view.findViewById(R.id.lista_personalizada_emissao);
    TextView nome = (TextView)
            view.findViewById(R.id.lista_personalizada_nome);
    TextView devendo = (TextView)
            view.findViewById(R.id.lista_personalizada_deve);
    TextView valorini = (TextView)
            view.findViewById(R.id.lista_personalizada_valorini);
    TextView status = (TextView)
            view.findViewById(R.id.lista_personalizada_status);
    TextView id = (TextView)
            view.findViewById(R.id.lista_personalizada_id);

    vencimento.setText(curso.getVencimento());
    emissao.setText(curso.getEmissao());
    nome.setText(curso.getNome2());
    devendo.setText(curso.getDevendo());
    valorini.setText(curso.getValorini());
    status.setText(curso.getStatus2());
    id.setText(curso.getId2());

    return view;
}
}

错误仅发生在列表视图中的插入中,因为正常使用cardview时,它不会显示错误

1 个答案:

答案 0 :(得分:0)

这种膨胀异常是由于您的可绘制资产规模较大造成的。 删除背景drawable到适当的文件夹,如drawable-hdpi或使用颜色代码来获得正确的颜色。