gpt4 book ai didi

android - MaterialCardView 内的 subview 缩小并消失

转载 作者:搜寻专家 更新时间:2023-11-01 07:42:16 30 4
gpt4 key购买 nike

android.support.design.card.MaterialCardView 已在原生 axml 布局中使用,并具有如下所示的 subview ,我的目标是在某些情况下保持切换边框即笔画事件发生,例如:按钮单击并恢复它,但是 strokeWidth 的每一次变化都会逐渐缩小 subview ,最后宽度和高度变为 0,使内部 View 完全消失。

MaterialCardView布局代码:


<?xml version="1.0" encoding="utf-8"?>
<android.support.design.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
app:cardCornerRadius="10dp"
app:strokeColor="#123456"
app:strokeWidth="3dp"
android:id="@+id/material_card"
android:padding="5dp"
android:layout_gravity="center_horizontal">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="240dp"
android:orientation="vertical"
android:padding="8dp"
android:id="@+id/linearLayoutCard">
<Button android:id="@+id/button"
android:text="Click me"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/textview"
android:text ="Border in"
android:layout_below="@id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.design.card.MaterialCardView>

PageRenderer 代码


  public void OnClick(Android.Views.View v)
{
// throw new NotImplementedException();
if (_yes)
{
material_card.StrokeColor = Android.Graphics.Color.ParseColor("#FFFFFF");
material_card.StrokeWidth = 0;
//material_card.LayoutParameters.LayoutAnimationParameters
linearLayoutCard?.SetMinimumHeight(material_card.Height+20);
linearLayoutCard?.SetMinimumWidth(material_card.Width+20);
linearLayoutCard.SetPadding(0, 0, 0, 0);
textview.Text = "Border out";
_yes = false;
// return true;
}
else
{
material_card.StrokeColor = Android.Graphics.Color.ParseColor("#123456");
material_card.StrokeWidth = 20;
linearLayoutCard?.SetMinimumHeight(material_card.Height);
linearLayoutCard?.SetMinimumWidth(material_card.Width);
linearLayoutCard.SetPadding(0, 0, 0, 0);
textview.Text = "Border in";
_yes = true;
//return true;
}
}

点击几下后:

Issue_image

我尝试使用其他布局 RelativeLayout 可以正常工作,还尝试增加 LinearLayout 的高度和宽度并将填充设置为 0 到最小,如上所示,这也不起作用,同时调试我注意到 MaterialCardView 触发了填充,这可能导致它缩小。还尝试将 cardview 的填充设置为 0,但仍然没有成功。

material_card.SetPadding(0, 0, 0, 0);
linearLayoutCard.LayoutParameters.Width = material_card.Width;
linearLayoutCard.LayoutParameters.Height =material_card.Height;

为什么内部 View 没有设置更高的宽度,因为它映射到 match_parent/fill_parent

Github 上的完整代码:github.com/pmahend1/TestMaterialCardView

最佳答案

此类似乎存在问题,导致其内容填充在更改 StrokeWidth 值后不断增加。

每次使用这行代码将 StrokeWith 设置为 0 时,请尝试重置 ContentPadding:

material_card.SetContentPadding(0, 0, 0, 0);

希望这有帮助。-

关于android - MaterialCardView 内的 subview 缩小并消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54025388/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com