[英]How to render html by div tag in android
I have HTML and I can use Webview to render the HTML and display it in the app.我有 HTML,我可以使用 Webview 渲染 HTML 并将其显示在应用程序中。 But it is not as straight forward.但这并不那么简单。
I have sections in the HTML separated by div tags.我在 HTML 中有部分由 div 标签分隔。
So how do you render it in the app?那么如何在应用程序中呈现它呢?
I don't want to use Webview, Cardview would be great!我不想使用 Webview,Cardview 会很棒!
To achieve this, Use the standard RecyclerView and create an adapter which extends RecyclerView.Adapter .为此,请使用标准RecyclerView并创建一个扩展RecyclerView.Adapter的适配器。 Each item in your list should then be implemented using the CardView然后应使用 CardView 实现列表中的每个项目
<android.support.v7.widget.CardView 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:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="@dimen/card_height"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/md_keylines"
android:layout_marginLeft="@dimen/md_keylines"
android:layout_marginRight="@dimen/md_keylines"
android:foreground="?attr/selectableItemBackground">
</android.support.v7.widget.CardView>
This will result into a layout similar to the image below.这将导致类似于下图的布局。 If you are not sure what a RecyclerView is or how to use it, please read more about it and the various android design widgets here https://github.com/googlecodelabs/android-design-library如果您不确定 RecyclerView 是什么或如何使用它,请在此处阅读有关它和各种 android 设计小部件的更多信息https://github.com/googlecodelabs/android-design-library
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.