작업을 구현하는 경우 FrameLayout
(자식이없는 레이아웃 XML 파일에 지정됨)을 사용하고 나서 필자가 필요로하는 Views
을 프로그래밍 방식으로 추가합니다. FrameLayout
에 처음 추가 된 View
은 항상 맨 아래에 있고 마지막 하나는 맨 위에 있습니다. FrameLayout
에있는 각 View
의 위치를 확인하려면 LayoutParams
을 사용합니다.
샘플 레이아웃 XML 파일 :
<?xml version="1.0" encoding="utf-8"?>
<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" >
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
는 활동의 onCreate()
방법에 FrameLayout
를 초기화합니다.
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frameLayout);
// set the imageview's layout parameters relative to the frame layout's parameters
FrameLayout.LayoutParams imageViewParams = new FrameLayout.LayoutParams(frameLayout.getWidth(), frameLayout.getHeight());
imageViewParams.gravity = Gravity.FILL;
imageViewParams.height = LayoutParams.MATCH_PARENT;
imageViewParams.width = LayoutParams.MATCH_PARENT;
// create the map image view
ImageView mapImageView = new ImageView(this);
mapImageView.setImageBitmap(mapBitmap);
mapImageView.setLayoutParams(imageViewParams);
// set the progressbar's layout parameters relative to the frame layout's parameters
FrameLayout.LayoutParams progressBarHorizontalParams = new FrameLayout.LayoutParams(frameLayout.getWidth(), frameLayout.getHeight());
progressBarHorizontalParams.gravity = Gravity.FILL;
progressBarHorizontalParams.height = LayoutParams.MATCH_PARENT;
progressBarHorizontalParams.width = LayoutParams.MATCH_PARENT;
// create the progress bar
ProgressBar progressBarHorizontal = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
progressBarHorizontal.setLayoutParams(progressBarHorizontalParams);
// make the progress bar transparent
progressBarHorizontal.setAlpha(0.3f);
// add the view(s) to the frame layout
frameLayout.addView(mapImageView);
frameLayout.addView(progressBarHorizontal);
이 정보가 도움이되기를 바랍니다.
답변을 주셔서 감사합니다. iRuth, 유용한 코드를 추가해 주셔서 감사합니다! 귀하의 방법으로지도 이미지를 프레임 레이아웃으로 오버레이하는 방법을 알 수 있습니다. 한 가지 더 질문합니다. 어떻게 사운드 재생 진행률 "막대"를 오버레이 할 수 있습니까? – notchopra
'mapImageView'를 추가 한 후에'FrameLayout'에 추가하십시오. 내 대답에서 언급했듯이,'FrameLayout'에 추가 된 마지막 뷰가 맨 위에 있습니다. – iRuth
하지만 그건 내가 확신 할 수없는 부분입니다 - 어떻게 seekbar의 진행 부분을 분리하고 넓고 투명한 오버레이로 포맷해야합니까? – notchopra