【发布时间】:2017-03-28 08:21:34
【问题描述】:
我在 Android 应用中使用 Google 地方信息自动完成片段。当我直接在 LinearLayout 的顶层使用片段时,一切正常:
<LinearLayout ...>
<fragment
android:id="@+id/findRidePlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"/>
</LinearLayout>
这个布局导致这个 UI:
如您所见,小部件周围没有边框,而它下方的 TextView 有黑色边框。根据我的阅读,在片段周围设置边框的一个技巧是将该片段嵌入到 CardView 中。这个方法其实是谷歌的official documentation推荐的。考虑以下修改后的布局:
<LinearLayout ...>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="left"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/main_border">
<fragment
android:id="@+id/findRidePlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"/>
</android.support.v7.widget.CardView>
</LinearLayout>
这里的技巧是给 CardView 一个背景,上面有 Google Places 片段,这样前者会显示为后者的边框。
但是这种修改后的布局会导致应用崩溃。有谁知道为什么会崩溃,或者我如何在 Google PlaceAutocompleteFragment 周围设置边框?
【问题讨论】:
-
你能发布 logcat 错误吗?
-
在哪里可以找到错误输出?我是 Android 开发新手。
-
您可以在 Android Studio 的 Android Monitor 选项卡下找到它,也可以在 logcat 上找到它 选项卡,或者您可以在命令行或终端上键入
adb logcat
标签: android google-maps android-fragments autocomplete