安卓TextView中的重叠问题

6
这是一个与Google Place API集成的片段。 这是第一张图片: 选择位置前 在选择了一个地点后,它看起来像这样: 从Google Place API中选择位置后 这是XML文件。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp">

    <in.vaksys.ezyride.utils.PercentLinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:orientation="horizontal">

        <LinearLayout
            android:id="@+id/SearchGetFromLocation"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_widthPercent="90%">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="FROM"
                android:textColor="#ffffff"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/SearchFromMainName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Hyderabad"
                android:textColor="#FFFFFF"
                android:textSize="30sp" />

            <TextView
                android:id="@+id/SearchFromSubName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Madhapur cyber tower, Hitechcitysad"
                android:textColor="#FFFFFF" />

        </LinearLayout>

        <ImageView
            android:id="@+id/SearchGetCurrentLocation"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:scaleType="fitEnd"
            android:src="@drawable/ic_near_me_white_24dp"
            app:layout_widthPercent="10%" />


    </in.vaksys.ezyride.utils.PercentLinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#CCC" />

    <in.vaksys.ezyride.utils.PercentLinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:orientation="horizontal">

        <LinearLayout
            android:id="@+id/SearchGetToLocation"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:orientation="vertical"
            app:layout_widthPercent="90%">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TO"
                android:textColor="#FFFFFF"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/SearchToMainName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Seconderabad"
                android:textColor="#FFFFFF"
                android:textSize="30sp" />

            <TextView
                android:id="@+id/SearchToSubName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:maxLines="2"
                android:text="Seconderabad railway stasion, Secondrabad"
                android:textColor="#FFFFFF" />

        </LinearLayout>

        <ImageView
            android:id="@+id/Search_btn_swap"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:scaleType="fitStart"
            android:src="@drawable/swap"
            app:layout_widthPercent="10%" />
    </in.vaksys.ezyride.utils.PercentLinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#CCC" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="90dp"
        android:gravity="center"
        android:orientation="vertical">

        <Button
            android:id="@+id/btn_search_ride"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_margin="10dp"
            android:background="@drawable/buttonshape"
            android:text="@string/search_ride"
            android:textColor="#FFFFFF" />

        <Button
            android:id="@+id/btn_offer_ride"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_margin="10dp"
            android:background="@drawable/buttonshape"
            android:text="@string/offer_ride"
            android:textColor="#FFFFFF" />
    </LinearLayout>

</LinearLayout>

这里是一个XML文件,在这里我没有发现任何问题。

Java文件:

private void ChooseFromLoc() {
    AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
            .setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
            .build();
    try {
        Intent intent =
                new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
//                                    .setBoundsBias(new LatLngBounds(new LatLng(), new LatLng()))
                            .build(getActivity());
            startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE_FROM);
        } catch (GooglePlayServicesRepairableException e) {
            GoogleApiAvailability.getInstance().getErrorDialog(getActivity(), e.getConnectionStatusCode(),
                    0 /* requestCode */).show();
        } catch (GooglePlayServicesNotAvailableException e) {
            String message = "Google Play Services is not available: " +
                    GoogleApiAvailability.getInstance().getErrorString(e.errorCode);
            Log.e(TAG, " ajsd : " + message);
            Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
        }
    }

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE_FROM) {
            if (resultCode == Activity.RESULT_OK) {
                Place place = PlaceAutocomplete.getPlace(getActivity(), data);
            SearchFromMainName.setText(place.getName());
            SearchFromSubName.setText(place.getAddress());
            LatLng FromLatLng = place.getLatLng();

            FromLat = FromLatLng.latitude;
            FromLng = FromLatLng.longitude;


        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status status = PlaceAutocomplete.getStatus(getActivity(), data);
            Log.e(TAG, "hehh : " + status.getStatusMessage());

        } else if (resultCode == Activity.RESULT_CANCELED) {
            // TODO: 23-06-2016 The user canceled the operation.
        }
    }
}

有人能否解释一下为什么会出现这种重叠的情况?

你是否正在使用ScrollView?同时请添加你的Activity类和布局文件。 - Zoe stands with Ukraine
请检查您的两个片段的主布局是否包含背景。 - Chirag Arora
我没有使用ScrollView。 等一下,我会上传我的XML文件@Polarbear0106 - Harsh Dalwadi
@YasinKaçmaz 我按照你给的链接保存了代码,但是仍然出现相同的问题。请检查一下。 - Harsh Dalwadi
1
@HarshDalwadi,然后您可以在活动中连接并启动活动以获取结果,并通过活动更改片段文本视图。 - Yasin Kaçmaz
显示剩余11条评论
1个回答

3

根据您所说,您正在使用导航抽屉,那么请确保在更改选项时,如果添加了一个片段,则应替换为另一个片段。 因此,请检查是否在一个框架中添加了多个片段。


2
哦,是的,我昨天尝试了那个方法,解决了问题。谢谢。 - Harsh Dalwadi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接