如何在android中处理地方自动完成片段的可见性

问题描述 投票:1回答:2

我有这个xml代码

<fragment
        android:id="@+id/place_autocomplete_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"/>

和java代码

PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
                getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

        autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                // TODO: Get info about the selected place.
                Log.i(TAG, "Place: " + place.getName());
            }

            @Override
            public void onError(Status status) {
                // TODO: Handle the error.
                Log.i(TAG, "An error occurred: " + status);
            }
        });

我想做一个自动完成碎片,在开始时看不见,当我点击按钮变得可见。我怎样才能做到这一点?对不起我的英语不好。谢谢!

android
2个回答
1
投票
autocompleteFragment.getView().setVisibility(View.GONE);

0
投票

PlaceAutocompleteFragment放在RelativeLayoutLinearLayout中,并根据需要使用其属性设置可见性。

<RelativeLayout
  android:id="@+id/rlSearchPlacement"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_marginTop="10dp"
  android:layout_marginRight="5dp"
  android:layout_marginLeft="5dp"
  android:background="@color/bg_white">
<fragment
    android:id="@+id/placeAutoFragment"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />
</RelativeLayout>

使用此代码隐藏布局:

RelativeLayout rlSearchPlace = (RelativeLayout) findViewById(R.id.rlSearchPlacement);
rlSearchPlace.setVisibility (View.GONE);
© www.soinside.com 2019 - 2024. All rights reserved.