渲染问题与TabLayout和ViewHolder

huangapple go评论49阅读模式
英文:

Render Problems with TabLayout and ViewHolder

问题

I am currently unable to render an activity with just a TabLayout and ViewPager. I am getting this error:

Style ResourceReference{namespace=apk/res-auto, type=attr, name=textAppearanceButton} is not of type STYLE (instead attr)

From the following code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent"
    android:layout_height="match_parent"
    tools:context=".CompoundInterest">

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="409dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="86dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.tabs.TabItem
            android:id="@+id/tabAbout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="About" />

        <com.google.android.material.tabs.TabItem
            android:id="@+id/tabCalculator"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Calculator" />

    </com.google.android.material.tabs.TabLayout>

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tabLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>

I added the TabLayout and ViewPager to an otherwise blank, new layout and they have never rendered, even after being 'connected' to the fragments.

英文:

I am currently unable to render am activity with just a TabLayout and ViewPager. I am getting this error:

Style ResourceReference{namespace=apk/res-auto, type=attr, name=textAppearanceButton} is not of type STYLE (instead attr)

From the following code:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    tools:context=&quot;.CompoundInterest&quot;&gt;

    &lt;com.google.android.material.tabs.TabLayout
        android:id=&quot;@+id/tabLayout&quot;
        android:layout_width=&quot;409dp&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:layout_marginTop=&quot;86dp&quot;
        app:layout_constraintEnd_toEndOf=&quot;parent&quot;
        app:layout_constraintStart_toStartOf=&quot;parent&quot;
        app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;

        &lt;com.google.android.material.tabs.TabItem
            android:id=&quot;@+id/tabAbout&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:text=&quot;About&quot; /&gt;

        &lt;com.google.android.material.tabs.TabItem
            android:id=&quot;@+id/tabCalculator&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:text=&quot;Calculator&quot; /&gt;

    &lt;/com.google.android.material.tabs.TabLayout&gt;

    &lt;androidx.viewpager.widget.ViewPager
        android:id=&quot;@+id/viewpager&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;0dp&quot;
        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
        app:layout_constraintEnd_toEndOf=&quot;parent&quot;
        app:layout_constraintStart_toStartOf=&quot;parent&quot;
        app:layout_constraintTop_toBottomOf=&quot;@id/tabLayout&quot; /&gt;
&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;

I added the TabLayout and ViewPager to an otherwise blank, new layout and they have never rendered, even after being 'connected' to the fragments.

答案1

得分: 9

前往Android视图,找到Gradle Scripts - build.gradle(Module: App),然后进行编辑。

implementation &#39;com.google.android.material:material:1.9.0&#39;

更改为

implementation &#39;com.google.android.material:material:1.7.0&#39;

最后,点击与Gradle文件同步项目,等待一分钟,就可以了。

英文:

Go to the Android View, find the Gradle Scripts - build.gralde(Module :App) then edit it.
change

implementation &#39;com.google.android.material:material:1.9.0&#39;

to

implementation &#39;com.google.android.material:material:1.7.0&#39;

Finally, click Sync Project with Gradle Files, wait a minute, it would be fine.

答案2

得分: 4

有关版本1.8.0似乎存在问题。

其他Material Design示例
TabLayout中的TabItems也存在渲染问题。

降级到1.7.0可以正常工作。

英文:

There seems to be a problem with version 1.8.0.

Other Material Design examples
TabItems in TabLaout are also having rendering issues.

Downgrading to 1.7.0 works fine.

huangapple
  • 本文由 发表于 2023年2月27日 00:26:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75573385.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定