0
votes

Je veux créer une mise en page avec un arrière-plan avec deux parties différentes, la partie supérieure aura une couleur d'arrière-plan différente et la partie inférieure aura une couleur différente

La vue extérieure doit également avoir des coins arrondis.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ffffff"></solid>
    <corners android:radius="10dp" />
    <stroke
        android:width="@dimen/dimen_1"
        android:color="#1877ee" />
</shape>

 codezlab card image


0 commentaires

3 Réponses :


0
votes

Pourquoi ne pas simplement utiliser une mise en page sur une autre mise en page?

Par exemple, une mise en page linéaire parent dans son ensemble et deux mises en page linéaires enfants avec des poids égaux et des arrière-plans différents:

<?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"
android:weightSum="2"> 

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical"
    android:background="#FFEB3B">
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical"
    android:background="#CC2323">
</LinearLayout>

</LinearLayout>

entrez la description de l'image ici


2 commentaires

comme je l'ai mentionné, il faut aussi des coins arrondis et le conteneur extérieur doit avoir une hauteur wrap_content


Pour obtenir un arrière-plan coloré avec des couleurs arrondies, regardez cette question et les différentes réponses: stackoverflow.com/questions/8930555/… Et si vous voulez que le conteneur extérieur soit wrap_content, alors pourquoi ne pas simplement changer son attribut de hauteur en cela ? Si la mise en page entière doit avoir des coins arrondis, vous voudrez probablement regarder dans CardViews: developer.android.com/reference/android/support/v7/widget/...



0
votes
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:background="@drawable/round_corners"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:weightSum="2"> 

    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_weight="1"
      android:orientation="vertical"
      android:background="@color/upper_one"> //code for layout for adjusting height </LinearLayout>

   <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_weight="1"
     android:orientation="vertical"
     android:background="@color/lower_color"> //code for layout for adjusting height</LinearLayout>
</LinearLayout>
You can fix the height or use wrap content to height and adjust view height inside linearlayouts 

0 commentaires

0
votes

Vous pouvez peut-être utiliser un dessin personnalisé:

Rendre un nouveau dessinable (border_up.xml) en utilisant ce code:

<LinearLayout
    android:weightSum="2"
    android:orientation="vertical"
    android:layout_width="120dp"
    android:layout_height="200dp"
    android:layout_marginTop="50dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="@color/colorWhite"
        android:gravity="center_horizontal|center_vertical"
        android:background="@drawable/border_up"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/colorWhite"
        android:gravity="center_horizontal|center_vertical"
        android:background="@drawable/border_down"
        android:layout_weight="1"
        android:text="TextView" />
</LinearLayout>

Et border_down.xml:

<corners android:topLeftRadius="0dp"
    android:topRightRadius="0dp"
    android:bottomLeftRadius="10dp"
    android:bottomRightRadius="10dp" />
<solid
    android:color="@color/colorAccent"/>

Dans votre mise en page, créez une mise en page linéaire ou une vue de texte en utilisant ci-dessus dessinable:

<corners android:topLeftRadius="10dp"
    android:topRightRadius="10dp"
    android:bottomLeftRadius="0dp"
    android:bottomRightRadius="0dp" />
<solid
    android:color="@color/colorPrimary"/>

 entrez la description de l'image ici p >


0 commentaires