0

Google지도 위에 TextView를 표시하는 데 문제가 있습니다. onCreate 메서드 중 FrameLayout에 MapFragment를 프로그래밍 방식으로 추가하고 TextView가 XML 파일에 있습니다. TextView가 제대로 표시되었지만 MapFragment가 FrameView에 추가되면 TextView가 숨겨집니다. StackOverflow에서 이미 검색했지만, XML에서 정적 MapFragment를 사용하여 찾을 수있는 모든 비슷한 주제가 있습니다. 여기 Google지도에 라벨 표시

내 코드입니다 : SRC/자바/SearchMapFragment.java

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    ... 
    mMapFragment = MapFragment.newInstance(options); 
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); 
    fragmentTransaction.add(R.id.map_layout,mMapFragment); 
    fragmentTransaction.commit(); 
    ((TextView)rootView.findViewById(R.id.map_label)).setVisibility(View.VISIBLE); 
    ... 
} 

내 XML의 FIL : 고해상도/레이아웃/fragment_search_map.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:id="@+id/search_map_wrapper_layout" 
    tools:context="com.appsolute.ParkYoo.SearchMapFragment"> 

    <FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/map_layout" 
     android:layout_weight="100"> 

     <TextView style="@style/DarkBlueText" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="New Text" 
      android:id="@+id/map_label" 
      android:gravity="center" 
      android:layout_marginTop="15dp" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:visibility="gone"/> 

    </FrameLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_weight="1"> 

     <FrameLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/search_map_frame_layout"> 

      <Button style="@style/WhiteText" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Lancer la recherche" 
       android:layout_margin="5dp" 
       android:id="@+id/launch_search" 
       android:background="@drawable/lancer" /> 

     </FrameLayout> 
    </LinearLayout> 
</LinearLayout> 

어떤 도움을 크게 감사 감사하겠습니다 사전에!

+0

당신이지도에서 동적 오버레이 텍스트 뷰를 만들려고 있나요? – Mohit

+0

어떻게해야하는지 알았다면 그것을했을 것입니다. 프로그래밍 방식으로 TextView를 추가 하시겠습니까? – user3476114

+0

LinearLayout 대신 RelativeLayout을 사용하려고 했습니까? TextView를 배치 할 수 있습니다. –

답변

1

마지막으로 답변을 찾았습니다. 기본적으로 나는 안드로이드에서 레이아웃 파일의 xml 아키텍처가 "back to front"였다고 생각합니다. XML 레이아웃 파일을 낮추면할수록 위젯이 더 많이 나타납니다. 따라서 위젯은 다른 위젯 위에 놓입니다.

그래서 TextLayout을 xml 파일에 넣으려고했지만 TextLayout은 동일한 것으로 판명되었습니다. 아마도 FrameLayout에 런타임에 FrameLayout에 추가 되었기 때문입니다. 따라서 마지막으로 TextLoader가 추가되어 겹치기 때문에 TextView가 onCreate 메소드.

내가이처럼 내 XML을 재 작업 한 내 문제를 해결하려면

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:id="@+id/search_map_wrapper_layout" 
    android:gravity="" 
    tools:context="com.appsolute.ParkYoo.SearchMapFragment"> 

    <FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/map_layout_leave_place" 
     android:layout_above="@+id/utility_linear_layout"> 

    </FrameLayout> 

    <FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="20dp" 
     android:id="@+id/leave_place_label"> 

    </FrameLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/utility_linear_layout" 
     android:orientation="vertical" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentBottom="true"> 

     <TextView style="@style/DarkBlueText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:id="@+id/street_leave_parking_spot" 
      android:layout_marginTop="10dp" 
      android:text="Rue X"/> 

     <TextView style="@style/TitleText" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:id="@+id/city_leave_parking_spot" 
      android:paddingBottom="15dp" 
      android:background="@drawable/discontinued_line" 
      android:text="75009 PARIS"/> 

     <Button style="@style/WhiteText" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:layout_marginBottom="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:text="Mémoriser ma place" 
      android:id="@+id/remember_parking_spot" 
      android:background="@drawable/lancer" 
      android:layout_gravity="center_horizontal|bottom"/> 

     </LinearLayout> 

</RelativeLayout> 

첫 번째 FrameLayout이 (map_layout_leave_place)이 가장 깊은이며, 내지도가 표시되는 위치입니다. 두 번째 FrameLayout (leave_place_label)은 내 TextView가 Google지도 레이아웃 위에 배치되어 있고 현재는 비어있는 곳입니다. 나머지는 런타임에 발생합니다.

leave_place_label에서 호스팅 할 버튼을 클릭하면 일반 조각 트랜잭션을 사용하여 런타임에 추가 할 TextView 만 포함 된 LabelFragment를 만들었습니다.

LabelFragment frag = LabelFragment.newInstance(); 
FragmentTransaction ft = getFragmentManager().beginTransaction(); 
ft.add(R.id.leave_place_label,frag); 
ft.commit(); 

그리고 여기가 자극이 수행합니다

https://drive.google.com/file/d/0B1KRFmgxHcLtMEY3dDQ1c0NRYWM/edit?usp=sharing