我的Flutter应用程序使用Google Pay作为付款方式。在these guidelines之后,它们提供XML按钮(我从未处理过)。
如何使用dart将这些按钮之一添加到flutter小部件?
最佳答案
laying out content for Android versus Flutter有不同的实现。layout/googlepay_button.xml
布局有效地描述了按钮的显示方式,并且drawable/googlepay_button_content.xml
包含Google Pay按钮的VectorDrawable
文件。 flutter_svg
应该可以帮助您渲染图像的内容。
为了使其与Flutter一起使用,您需要将xml布局重现为Flutter小部件树。
样本布局black/res/layout/googlepay_button.xml
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="48sp"
android:background="@drawable/googlepay_button_no_shadow_background"
android:paddingTop="2sp"
android:contentDescription="@string/googlepay_button_content_description">
<LinearLayout
android:duplicateParentState="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scaleType="fitCenter"
android:duplicateParentState="true"
android:src="@drawable/googlepay_button_content"/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:duplicateParentState="true"
android:src="@drawable/googlepay_button_overlay"/>
</RelativeLayout>
关于android-layout - 如何在Flutter中添加XML Google Pay按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59332528/