android:drawableEnd在迁移到Material Design时导致崩溃

时间:2018-06-09 10:05:28

标签: android android-layout material-design right-to-left

我正在将旧应用程序迁移到Material Design,主要是转换为ConstraintLayout和CoordinatorLayout并添加RTL支持(minSdk = 14 targetSdk = 26)。

android:drawableEnd在Material之前使用这些SDK设置。现在它导致崩溃,但使用android:drawable不会。一个很好的例子:

view.xml用:

<TextView
    android:id="@+id/StatisticsField"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="19dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    android:gravity="start"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/StatisticsLabel"
    app:layout_constraintTop_toTopOf="parent"
    style="@style/FormFieldValueWithArrowStyle"/>

styles.xml:

<style name="FormFieldValueStyle">
    <item name="android:textAppearance">@style/TextAppearance.AppCompat.Medium</item>
    <item name="android:gravity">start|center_vertical</item>
    <item name="android:layout_gravity">center_vertical</item>
    <item name="android:layout_weight">1</item>
</style>

<style name="FormFieldValueWithArrowStyle" parent="FormFieldValueStyle">
    <item name="android:drawableEnd">?FormFieldArrowIcon</item
</style>

styles-ldrtl.xml(实际上在values-ldrtl中):

<style name="FormFieldValueWithArrowStyle" parent="FormFieldValueStyle">
    <item name="android:drawableEnd">?FormFieldArrowIconRTL</item>
</style>

堆栈跟踪:

> E/AndroidRuntime: FATAL EXCEPTION: main
>     Process: org.myapp, PID: 10536
>     android.view.InflateException: Binary XML file line #28: Binary XML file line #28: Error inflating class TextView
>     Caused by: android.view.InflateException: Binary XML file line #28: Error inflating class TextView
>     Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 74: TypedValue{t=0x2/d=0x7f040003 a=4}
>         at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:946)
>         at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
>         at android.widget.TextView.<init>(TextView.java:1034)
>         at android.widget.TextView.<init>(TextView.java:869)
>         at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:76)
>         at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:72)
>         at android.support.v7.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:176)
>         at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:101)
>         at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1035)
>         at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)
>         at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
>         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
>         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
>         at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
>         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
>         at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
>         at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
>         at org.myapp.SummaryActivity.onCreateView(SummaryActivity.java:48)
>         at android.support.v4.app.Fragment.performCreateView(Fragment.java:2346)
>         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1428)
>         at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
>         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
>         at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
>         at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2596)
>         at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2383)
>         at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
>         at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
>         at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:784)
>         at org.skydiveapplibrary.ui.ViewPagerAdapter.finishUpdate(ViewPagerAdapter.java:206)
>         at android.support.v4.view.ViewPager.populate(ViewPager.java:1238)
>         at android.support.v4.view.ViewPager.populate(ViewPager.java:1086)
>         at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1616)
>         at android.view.View.measure(View.java:23165)
>         at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1210)
>         at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1550)
>         at android.view.View.measure(View.java:23165)
>         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
>         at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:739)
>         at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:91)
>         at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1361)
>         at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:809)
>         at android.view.View.measure(View.java:23165)
>         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
>         at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
>         at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
> E/AndroidRuntime:     at android.view.View.measure(View.java:23165)
>         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
>         at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:400)
>         at android.view.View.measure(View.java:23165)
>         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
>         at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
>         at android.view.View.measure(View.java:23165)
>         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
>         at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
>         at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
>         at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
>         at android.view.View.measure(View.java:23165)
>         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
>         at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
>         at com.android.internal.policy.DecorView.onMeasure(DecorView.java:720)
>         at android.view.View.measure(View.java:23165)
>         at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2689)
>         at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1555)
>         at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1826)
>         at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1443)
>         at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7125)
>         at android.view.Choreographer$CallbackRecord.run(Choreographer.java:935)
>         at android.view.Choreographer.doCallbacks(Choreographer.java:747)
>         at android.view.Choreographer.doFrame(Choreographer.java:682)
>         at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:921)
>         at android.os.Handler.handleCallback(Handler.java:873)
>         at android.os.Handler.dispatchMessage(Handler.java:99)
>         at android.os.Looper.loop(Looper.java:164)
>         at android.app.ActivityThread.main(ActivityThread.java:6649)
>         at java.lang.reflect.Method.invoke(Native Method)
>         at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
>         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)

0 个答案:

没有答案