![](/img/trans.png)
[英]Android Java Use a cardview to display the items of a gridview
[英]How to use cardview in android
我尝试进行卡片查看,但我不明白如何使用 textview 和 webview 进行滚动页面。 有人可以告诉我卡片视图的基本代码吗?
<TextView
android:id="@+id/textView4"
android:layout_width="432dp"
android:layout_height="510dp"
android:text="TextView" />
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
我希望我的应用程序页面具有文本视图和用户可以滚动的 webview。 所以我认为我可以用 cardview 做到这一点,但我无法理解我在视频中看到的 cardview 代码。 如何仅使用 textview 和 cardview 使用此 function?
我在 CardView 上看过一些视频,但我不能用他们的代码来做我想做的事。 我只有一个文本视图和一个 webview 我希望用户可以滚动。 有人会显示一些卡片视图的基本代码,并解释它的作用吗?
添加卡片视图依赖项
dependencies {
implementation 'androidx.cardview:cardview:1.0.0'
}
在布局中添加卡片视图
<androidx.cardview.widget.CardView
android:id="@+id/card_view"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@color/grey_300"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="5dp"
card_view:cardUseCompatPadding="true">
<TextView
android:id="@+id/textView4"
android:layout_width="432dp"
android:layout_height="510dp"
android:text="TextView" />
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</<androidx.cardview.widget.CardView>
我有一个错误,这是我的代码
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
对于 xml
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="293dp"
app:cardBackgroundColor="@color/card"
app:cardCornerRadius="10dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<TextView
android:id="@+id/textView4"
android:layout_width="432dp"
android:layout_height="510dp"
android:text="TextView" />
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="WebViewLayout" />
</android.support.v7.widget.CardView>
使用这行代码,应用程序停止,我只尝试使用依赖项行,我没有放置 XML 的代码行,只有依赖项实现 cardview 行和隐藏并没有停止,但是当我放置代码行时对于 XML 文件,应用程序停止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.