如何在Android CardView中放大和缩小布局

时间:2018-11-16 06:48:26

标签: android android-layout arraylist zoom android-cardview

我需要您的帮助,以指导我通过单击来使用Android CardView中的放大和缩小布局。

卡视图已连接到arrayadapter。

是否还可以在ConstraintLayout上执行此操作(ConstraintLayout在LinearLayout旁边?

卡片XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@android:color/white"
    android:clipToPadding="false"
    android:outlineProvider="bounds"
    android:paddingBottom="10sp"
    android:paddingLeft="15sp"
    android:paddingRight="15sp"
    android:paddingTop="5sp">

    <android.support.v7.widget.CardView
        android:id="@+id/cardViewxx"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:elevation="2dp"

        app:cardCornerRadius="2dp">


        <LinearLayout
            android:id="@+id/defense"
            android:layout_width="342dp"
            android:layout_height="458dp"
            android:layout_gravity="center"
            android:background="@android:color/white"
            android:orientation="vertical">


            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="238dp">

                <TextView
                    android:id="@+id/scoretestViewxx"
                    android:layout_width="169dp"
                    android:layout_height="62dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginBottom="8dp"
                    android:gravity="center"
                    android:onClick="goTobar"
                    android:text="0"
                    android:textAllCaps="true"
                    android:textColor="@android:color/holo_red_dark"
                    android:textSize="40sp"
                    android:textStyle="bold"
                    app:fontFamily="@font/wcmanonegrabta"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"

                    app:layout_constraintHorizontal_bias="0.502"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.05" />

                <de.hdodenhof.circleimageview.CircleImageView
                    android:id="@+id/imagexx"
                    android:layout_width="140dp"
                    android:layout_height="141dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginBottom="8dp"
                    android:background="@android:color/transparent"
                    android:scaleType="centerCrop"
                    app:civ_border_color="#ba000000"
                    app:civ_border_width="1dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="1.0" />

                <ImageView
                    android:id="@+id/imgRandomxx"
                    android:layout_width="137dp"
                    android:layout_height="2dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginBottom="8dp"
                    android:layout_weight="1"
                    android:background="@android:color/white"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.507"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="1.0" />

            </android.support.constraint.ConstraintLayout>

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="199dp"
                >

                <TextView
                    android:id="@+id/namexx"
                    android:layout_width="178dp"
                    android:layout_height="25dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:layout_marginBottom="8dp"
                    android:background="@android:color/transparent"
                    android:gravity="center|left"
                    android:paddingLeft="20sp"
                    android:textColor="@android:color/black"
                    android:textSize="19sp"
                    app:fontFamily="@font/arsenal"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.528"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.0"
                    tools:text="hello" />

                <TextView
                    android:id="@+id/textViewxx"
                    android:layout_width="140dp"
                    android:layout_height="28dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginBottom="8dp"
                    android:text="  job summery"
                    android:textColor="@android:color/black"
                    android:textSize="19sp"
                    app:fontFamily="@font/arsenal"
                    app:layout_constraintBottom_toTopOf="@+id/textdiView7xx"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/namexx" />

                <TextView
                    android:id="@+id/textdiView7xx"
                    android:layout_width="291dp"
                    android:layout_height="104dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"


                    android:layout_marginRight="8dp"
                    android:layout_marginBottom="8dp"
                    android:ems="10"
                    android:text="TextView"
                    android:textColor="@android:color/black"
                    app:fontFamily="@font/arsenal"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.47"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.933" />



            </android.support.constraint.ConstraintLayout>

        </LinearLayout>
    </android.support.v7.widget.CardView>


</LinearLayout>

Arrayadapter

public class arrayAdapterxx extends ArrayAdapter<cardsxx>{

    Context context;

    public arrayAdapterxx(Context context, int resourceId, List<cardsxx> items){
        super(context, resourceId, items);
    }
    public View getView(int position, View convertView, ViewGroup parent){
        cardsxx card_item = getItem(position);

        if (convertView == null){
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.itemxx, parent, false);

        }

        TextView name = (TextView) convertView.findViewById(R.id.namexx);
        TextView mytest = (TextView) convertView.findViewById(R.id.scoretestViewxx);
        TextView OppsiteDiscription = (TextView) convertView.findViewById(R.id.textdiView7xx);
        ImageView image = (ImageView) convertView.findViewById(R.id.imagexx);
        ImageView image2 = (ImageView) convertView.findViewById(R.id.imgRandomxx);




        name.setText(card_item.getName());
        mytest.setText(card_item.getMytest());
        OppsiteDiscription.setText(card_item.getOppsiteDiscription());



        switch(card_item.getMytest()){
            case "5":
                image2.setImageResource(R.drawable.s_5);
                break;
            case "10":
                image2.setImageResource(R.drawable.s_10);
                break;

            default:
                image2.setImageResource(R.drawable.s_5);
                break;
        }


        switch(card_item.getProfileImageUrl()){
            case "default":
                Glide.with(convertView.getContext()).load(R.mipmap.ic_launcher).into(image);
                break;
            default:
                Glide.clear(image);
                Glide.with(convertView.getContext()).load(card_item.getProfileImageUrl()).into(image);
                break;
        }


        return convertView;

    }




}

卡型号

public class cardsxx {
    private String userId;
    private String name;
    private String mytest;
    private String OppsiteDiscription;


    private String profileImageUrl;

    public cardsxx(String userId, String name, String mytest, String OppsiteDiscription, String profileImageUrl){
        this.userId = userId;
        this.name = name;
        this.mytest = mytest;

        this.OppsiteDiscription = OppsiteDiscription;

        this.profileImageUrl = profileImageUrl;
    }


    public String getUserId(){
        return userId;
    }
    public void setUserID(String userID){
        this.userId = userId;
    }


    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name = name;
    }


    public String getMytest(){ return mytest; }
    public void setMytest(String mytest)
    {
        this.mytest = mytest;
    }


    public String getOppsiteDiscription(){ return OppsiteDiscription; }
   public void setOppsiteDiscription(String OppsiteDiscription) { this.OppsiteDiscription = OppsiteDiscription; }


    public String getProfileImageUrl(){

        return profileImageUrl;
    }

    public void setProfileImageUrl(String profileImageUrl){
        this.profileImageUrl = profileImageUrl;
    }



}

我如何在适配器旁边使用onclick事件来获得放大/缩小? ..

1 个答案:

答案 0 :(得分:0)

parent_source_id