我已经实现了新风格的可折叠工具栏。我使用与示例(Cheesesquare)演示应用程序相同的代码 - 当然在所有设备上都能正常工作。我需要帮助弄清楚我做的与示例不同(所以我的应用程序不会崩溃)。
我的应用程序在5.0+设备上运行良好,但在旧设备(OS 4.4.4)上崩溃时出现错误,我无法隔离到我的代码(没有引用我的项目在堆栈中的类)。 对我来说似乎很奇怪,这是特定于设备的(如果这是代码错误,它会在任何地方崩溃)
我有(试过,但没有帮助):
我看到一个相关的Bug已经打开(但没有分配):https://code.google.com/p/android/issues/detail?id=157919 有趣的是,这个错误说明没有在4.3上崩溃,但我没有设备方便。
关于如何调试此崩溃原因的建议?:
E/AndroidRuntime( 708): java.lang.IllegalArgumentException: radius must be > 0
E/AndroidRuntime( 708): at android.graphics.RadialGradient.<init>(RadialGradient.java:53)
E/AndroidRuntime( 708): at android.support.v7.widget.RoundRectDrawableWithShadow.buildShadowCorners(RoundRectDrawableWithShadow.java:285)
E/AndroidRuntime( 708): at android.support.v7.widget.RoundRectDrawableWithShadow.buildComponents(RoundRectDrawableWithShadow.java:307)
E/AndroidRuntime( 708): at android.support.v7.widget.RoundRectDrawableWithShadow.draw(RoundRectDrawableWithShadow.java:209)
E/AndroidRuntime( 708): at android.view.View.draw(View.java:15493)
E/AndroidRuntime( 708): at android.widget.FrameLayout.draw(FrameLayout.java:472)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14402)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime( 708): at android.view.View.draw(View.java:15222)
E/AndroidRuntime( 708): at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime( 708): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14397)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime( 708): at android.view.View.draw(View.java:15222)
E/AndroidRuntime( 708): at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime( 708): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime( 708): at android.view.View.draw(View.java:15511)
E/AndroidRuntime( 708): at android.widget.FrameLayout.draw(FrameLayout.java:472)
E/AndroidRuntime( 708): at android.support.v4.widget.NestedScrollView.draw(NestedScrollView.java:1679)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14402)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime( 708): at android.view.View.draw(View.java:15222)
E/AndroidRuntime( 708): at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime( 708): at android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1040)
E/AndroidRuntime( 708): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14397)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime( 708): at android.view.View.draw(View.java:15222)
E/AndroidRuntime( 708): at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime( 708): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime( 708): at android.view.View.draw(View.java:15511)
E/AndroidRuntime( 708): at android.widget.FrameLayout.draw(FrameLayout.java:472)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14402)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime( 708): at android.view.View.draw(View.java:15222)
E/AndroidRuntime( 708): at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime( 708): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14397)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime( 708): at android.view.View.draw(View.java:15222)
E/AndroidRuntime( 708): at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime( 708): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14397)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime( 708): at android.view.View.draw(View.java:15222)
E/AndroidRuntime( 708): at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime( 708): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14397)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime( 708): at android.view.View.draw(View.java:15222)
E/AndroidRuntime( 708): at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime( 708): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime( 708): at android.view.View.draw(View.java:15511)
E/AndroidRuntime( 708): at android.widget.FrameLayout.draw(FrameLayout.java:472)
E/AndroidRuntime( 708): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2623)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14402)
E/AndroidRuntime( 708): at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime( 708): at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1597)
E/AndroidRuntime( 708): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1469)
E/AndroidRuntime( 708): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2800)
E/AndroidRuntime( 708): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2666)
E/AndroidRuntime( 708): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2234)
E/AndroidRuntime( 708): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1267)
E/AndroidRuntime( 708): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6638)
E/AndroidRuntime( 708): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:813)
E/AndroidRuntime( 708): at android.view.Choreogra
我的活动:
public class PaymentActivity extends AppCompatActivity {
public static final String XTRA_DEVICENAME = "";
private static String deviceName;
private ItemDto deviceDto;
private Activity mActivity;
private OkHttpClient okclient;
//Views
private RelativeLayout infoLayout;
private TextView deviceOwner;
private TextView devicePrice;
private TextView deviceInfo;
private TextView payDurationTitle;
private TextView payPriceTitle;
private TextView payDurationText;
private TextView payPriceText;
private Button upBtn;
private Button downBtn;
private TextView incText;
private View incrDivider;
private FloatingActionButton fab;
private ProgressBar devInfoProgress;
private LinearLayout incrBtnView;
private int mIterVal = 1;
private Constants.ColorInfo colorTheme = Constants.ColorInfo.GREY;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivity = this;
Intent intent = getIntent();
deviceName = intent.getStringExtra(XTRA_DEVICENAME);
setTheme(ColorUtil.getThemeForDevice(deviceName));
colorTheme = ColorUtil.getColorTheme(deviceName);
setContentView(R.layout.act_payment);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
okclient = new OkHttpClient();
CollapsingToolbarLayout collapsingToolbar =
(CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsingToolbar.setTitle(deviceName.toUpperCase());
okclient = new OkHttpClient();
final ImageView imageView = (ImageView) findViewById(R.id.backdrop);
// todo get better default image
final String paymentIconUrl = "http://xxx/" + deviceName + "_lg.png";
Glide.with(mActivity)
.load(paymentIconUrl)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.ic_logo_allwhite)
.error(R.drawable.ic_logo_allwhite)
.into(imageView);
setupViews();
new GetItemInfoTask().execute(deviceName);
}
private void setupViews() {
infoLayout = (RelativeLayout) findViewById(R.id.device_info_layout);
infoLayout.setBackgroundColor(getResources().getColor(ColorUtil.getDeviceColor(deviceName, ColorUtil.COLOR_SECONDARY)));
incrBtnView = (LinearLayout) findViewById(R.id.incr_btn_view);
deviceOwner = (TextView) findViewById(R.id.info_owner);
devicePrice = (TextView) findViewById(R.id.info_price);
deviceInfo = (TextView) findViewById(R.id.info_max_amount);
payDurationTitle = (TextView) findViewById(R.id.paidDurationTitle);
payPriceTitle = (TextView) findViewById(R.id.paidAmountTitle);
payDurationText = (TextView) findViewById(R.id.paidDurationText);
payPriceText = (TextView) findViewById(R.id.paidAmountText);
devInfoProgress = (ProgressBar) findViewById(R.id.devinfo_progress);
devInfoProgress.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.card_white), android.graphics.PorterDuff.Mode.MULTIPLY);
Drawable tmpDrawable = ColorUtil.getTintedDrawable(mActivity, R.drawable.ic_attach_money, colorTheme.getSecondary());
payPriceTitle.setCompoundDrawablesWithIntrinsicBounds(tmpDrawable, null, null, null);
Drawable tmpDrawable2 = ColorUtil.getTintedDrawable(mActivity, R.drawable.ic_clock, colorTheme.getSecondary());
payDurationTitle.setCompoundDrawablesWithIntrinsicBounds(tmpDrawable2, null, null, null);
upBtn = (Button) findViewById(R.id.pay_inc_up_btn);
downBtn = (Button) findViewById(R.id.pay_inc_down_btn);
incText = (TextView) findViewById(R.id.pay_inc_text);
incrDivider = (View) findViewById(R.id.iter_divider);
upBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
...
}
});
downBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
...
}
});
upBtn.setBackground(mActivity.getResources().getDrawable(colorTheme.getSelectorId()));
downBtn.setBackground(mActivity.getResources().getDrawable(colorTheme.getSelectorId()));
fab = (FloatingActionButton) findViewById((R.id.pay_fab_btn));
//TODO - manually coloring FAB, should do with color state list
fab.setEnabled(false);
fab.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.grey_300)));
fab.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
fab.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.card_white)));
...
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_payment, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private class GetItemInfoTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
...
return null;
}
@Override
protected void onPostExecute(String result) {
...
}
@Override
protected void onPreExecute() {
devInfoProgress.setVisibility(View.VISIBLE);
}
@Override
protected void onProgressUpdate(Void... values) {
}
}
}
我的Layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/payments_backdrop_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:transitionName="device_img"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_200"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/device_info_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/info_owner"
style="@style/DeviceInfo" />
<TextView
android:id="@+id/info_price"
style="@style/DeviceInfo"
android:layout_below="@+id/info_owner"/>
<TextView
android:id="@+id/info_max_amount"
style="@style/DeviceInfo"
android:layout_below="@+id/info_price"
android:layout_marginBottom="@dimen/grid1" />
<ProgressBar
android:id="@+id/devinfo_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="@dimen/rythm48"
android:layout_height="@dimen/rythm48"
android:layout_toRightOf="@+id/info_price"
android:layout_marginRight="@dimen/grid5"
android:layout_marginTop="@dimen/grid1"
android:visibility="gone" />
</RelativeLayout>
<android.support.v7.widget.CardView
android:id="@+id/device_info_card"
style="@style/CardView"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/launch_title"
style="@style/CardTitle"
android:text="Current Amounts" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/confirm_text"
android:layout_marginBottom="@dimen/grid5"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/paidAmountTitle"
style="@style/TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_dollar"
android:gravity="center"
android:text="@string/paid_amount_title" />
<TextView
android:id="@+id/paidAmountText"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/paidDurationTitle"
style="@style/TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_clock"
android:gravity="center"
android:text="@string/paid_duration_title" />
<TextView
android:id="@+id/paidDurationText"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/iter_divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginBottom="@dimen/grid2"
android:layout_marginTop="@dimen/grid_5"
android:background="@color/grey_400"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/incr_btn_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/grid5"
android:layout_marginLeft="@dimen/grid4"
android:layout_marginRight="@dimen/grid4"
android:orientation="horizontal"
android:gravity="center"
android:weightSum="3"
android:visibility="gone">
<Button
android:id="@+id/pay_inc_down_btn"
style="@style/InfoButton"
android:layout_width="@dimen/rythm48"
android:layout_height="@dimen/rythm48"
android:text="-"
android:textSize="32sp"
android:layout_weight="1"/>
<TextView
android:id="@+id/pay_inc_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:gravity="center"
android:layout_marginRight="@dimen/grid2"
android:layout_marginLeft="@dimen/grid2"
android:textSize="24sp"
android:layout_weight="1"/>
<Button
android:id="@+id/pay_inc_up_btn"
style="@style/InfoButton"
android:layout_width="@dimen/rythm48"
android:layout_height="@dimen/rythm48"
android:text="+"
android:textSize="32sp"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/provider_card_view"
style="@style/CardView"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="6dp">
<fragment
android:id="@+id/provider_fragment"
android:name="com.cleartoken.pay.ui.frag.ProviderFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
style="@style/CardView"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Info"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/long_text" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/pay_fab_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/grid2"
android:clickable="true"
android:src="@drawable/ic_fab_enabled"
app:borderWidth="0dp"
app:layout_anchor="@id/device_info_card"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
CardView style.xml片段:
<style name="CardView">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_margin">@dimen/grid1</item>
</style>
注意:
我普遍使用相同的卡片样式。在第1法案中,这有效*(法案#1没有协调员布局的巨大差异)。
我的卡片XML看起来很普遍:
<android.support.v7.widget.CardView
android:id="@+id/device_info_card"
style="@style/CardView"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="6dp">
答案 0 :(得分:5)
在你的堆栈错误中,有一件事对我很突出。它似乎在4.4及以下,你的应用程序试图绘制一个大于实际手机宽度的gui。 RadialGradient错误对我没有意义,因为它应该大于屏幕大小而不是小于零。
/** Create a shader that draws a radial gradient given the center and radius.
@param centerX The x-coordinate of the center of the radius
@param centerY The y-coordinate of the center of the radius
@param radius Must be positive. The radius of the circle for this gradient.
@param colors The colors to be distributed between the center and edge of the circle
@param stops May be <code>null</code>. Valid values are between <code>0.0f</code> and
<code>1.0f</code>. The relative position of each corresponding color in
the colors array. If <code>null</code>, colors are distributed evenly
between the center and edge of the circle.
@param tileMode The Shader tiling mode
*/
public RadialGradient(float centerX, float centerY, float radius,
@NonNull int colors[], @Nullable float stops[], @NonNull TileMode tileMode) {
if (radius <= 0) {
throw new IllegalArgumentException("radius must be > 0");
}
if (colors.length < 2) {
throw new IllegalArgumentException("needs >= 2 number of colors");
}
if (stops != null && colors.length != stops.length) {
throw new IllegalArgumentException("color and position arrays must be of equal length");
}
mType = TYPE_COLORS_AND_POSITIONS;
mX = centerX;
mY = centerY;
mRadius = radius;
mColors = colors;
mPositions = stops;
mTileMode = tileMode;
init(nativeCreate1(centerX, centerY, radius, colors, stops, tileMode.nativeInt));
}
这是来自radialgradient类的片段。强制代码运行的一种方法是简单地编辑radialgradient类,如果你能做到这一点(Android Studio有办法做到这一点)。
我对此问题的解决方案是首先浏览您的xml文件,然后开始删除不常见的代码行/没有意义。像:
android:fitsSystemWindows="true"
fitSystemWindow Multiple Calls
您应该避免的另一件事是线性布局的权重和重量标签。并尝试将您的父窗口小部件设为RelativeLayout。
编辑:
经过一段时间的思考(仅仅2分钟),我意识到错误可能只是由于styles.xml的实现。您确定复制了在git repo中看到的所有文件夹吗?
有时候出现这种错误时,通常是因为没有使用相应的styles.xml添加了值-v21文件夹。
因此,如果您没有values-v21文件夹,请执行以下操作: - 在res文件夹下创建一个values-v21文件夹。 - 然后在values-v21文件夹下创建styles.xml文件夹并添加此代码。
<resources>
<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
答案 1 :(得分:3)
对于未来的人,我发现了我的问题 - 我使用的样式与框架使用的另一个样式名称相同( CardView )。
我将styles.xml文件中的名称更改为其他名称( MyCardView ),然后崩溃就消失了。
事后看来,我使用这个通用名称导致了回归。
答案 2 :(得分:1)
在L之前,CardView会在其内容中添加填充并绘制阴影 那个地区。此填充量等于maxCardElevation +(1 - cos45)*两侧的cornerRadius和maxCardElevation * 1.5 +(1 - cos45)* cornerRadius在顶部和底部。
由于填充用于偏移阴影的内容,因此无法设置 在CardView上填充。相反,您可以使用内容填充属性 在XML或setContentPadding(int,int,int,int)中设置代码 在Card的边缘和CardView的孩子之间填充。
检查所有wrap-parent
值。我认为代码中的某些位置正在更改此填充行为,导致mCornerRadius < 0
中buildShadowCorners
方法中的RoundRectDrawableWithShadow.java
。
这些链接可能有所帮助:
width and height must be > 0 error
答案 3 :(得分:1)
我有同样的问题,我发现我在cardview属性上有app:cardCornerRadius="0dp"
。当我删除它然后我的问题解决了。希望这有帮助
答案 4 :(得分:1)
我将项目主容器视为cardview,我将 cardCornerRadius 设置为0:
app:cardCornerRadius="0dp"
我把它改为:
app:cardCornerRadius="1dp"
现在效果很好。
我还使用android:fitsSystemWindows="true"
进行了测试,不为我做了更改。