亦余心之所善兮,虽九死其犹未悔。这篇文章主要讲述如何在Android CardView中放大和缩小布局相关的知识,希望能为你提供帮助。
【如何在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事件来缩放/缩小? ..
答案
if( // wants to zoom)
view.animate().scaleX(1.05f).scaleY(1.05f).setDuration(135);
else // stay there
view.animate().scaleX(1).scaleY(1).setDuration(135);
推荐阅读
- Android GridVIew根据方向更改列数
- Intellij Idea 2018.2.5 CE Android开发问题,android sdk v28是不稳定/渲染问题
- 如何在Android上一次性获取所有按钮ID
- Android - 任何Activity的根视图层次结构中存在的所有视图的相对路径生成器
- 在Android Studio中将Gradle从3.3升级到4.1后出错
- PC和Android设备之间的客户端 - 服务器连接问题
- Android Alpha内部版本无法登录。我在哪里可以查看日志文件()
- 如何在Android Studio中的模拟器上安装apk()
- windows7 64位官方旗舰版系统推荐