Android는 모든 것 위에 뷰를 오버레이합니까?
안드로이드의 모든 것 위에 뷰를 오버레이 할 수 있습니까?
iPhone에서는 새 뷰 frame.origin
를 (0,0)으로 설정 하고 너비와 높이를 너비와 높이로 설정 self.view
합니다. 에 추가하면 self.view
뒤에있는 콘텐츠를 덮는 오버레이 역할을하게됩니다 (또는 투명한 배경이있는 경우 뒤에보기를 표시 함).
안드로이드에 비슷한 기술이 있습니까? 뷰가 약간 다르다는 것을 알고 있지만 (세 가지 유형 (또는 그 이상 ...) relativelayout, linearlayout 및 framelayout이 있음) 모든 것 위에 뷰를 무차별 적으로 오버레이 할 수있는 방법이 있습니까?
간단하게 사용 RelativeLayout
하거나 FrameLayout
. 마지막 자식보기는 다른 모든 항목을 오버레이합니다.
Android는 Cocoa Touch SDK가 지원하지 않는 패턴 인 레이아웃 관리를 지원합니다. iPhone 용
레이아웃 은 모든 것을 절대적으로 배치하는 것을 의미합니다 (일부 strech 요소 제외). 안드로이드의 레이아웃은 아이들이 서로에 대해 배치된다는 것을 의미합니다.
예 (두 번째 EditText는 첫 번째 것을 완전히 덮습니다) :
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/root_view">
<EditText
android:layout_width="fill_parent"
android:id="@+id/editText1"
android:layout_height="fill_parent">
</EditText>
<EditText
android:layout_width="fill_parent"
android:id="@+id/editText2"
android:layout_height="fill_parent">
<requestFocus></requestFocus>
</EditText>
</FrameLayout>
FrameLayout
일종의 뷰 스택입니다. 특별한 경우를 위해 제작되었습니다.
RelativeLayout
꽤 강력합니다. 보기 A가 상위 레이아웃을 아래쪽 으로 정렬해야하고 , 보기 B가 A를 아래쪽에서 위쪽으로 정렬해야하는 등의 규칙을 정의 할 수 있습니다.
댓글에 따라 업데이트
일반적으로 콘텐츠를 setContentView(R.layout.your_layout)
in으로 설정합니다 onCreate
(레이아웃이 확장됩니다). 수동으로 할 수 있고을 호출 할 수 있습니다 setContentView(inflatedView)
. 차이가 없습니다.
뷰 자체는 단일 뷰 (예 TextView
:) 또는 복잡한 레이아웃 계층 (모든 레이아웃 자체가 뷰이므로 중첩 된 레이아웃) 일 수 있습니다.
setContentView
활동을 호출 한 후에 는 내용이 어떻게 생겼는지 알 수 (FrameLayout) findViewById(R.id.root_view)
있으며이 계층 구조 (일반 패턴 (ClassOfTheViewWithThisId) findViewById(R.id.declared_id_of_view)
)에서 보기를 검색하는 데 사용할 수 있습니다 .
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id = "@+id/Everything"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- other actual layout stuff here EVERYTHING HERE -->
</LinearLayout>
<LinearLayout
android:id="@+id/overlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right" >
</LinearLayout>
지금 당신이있는 LinearLayout에서 추가 한 뷰 android:id = "@+id/overlay"
와 오버레이로 나타납니다 중력 잘 = 선형 레이아웃에 android:id="@+id/Everything"
다음을 사용할 수 있습니다 bringToFront
.
View view=findViewById(R.id.btnStartGame);
view.bringToFront();
가장 좋은 방법은 ViewOverlay 입니다. Android JellyBeanMR2 (Api 18) 이후 모든 드로어 블을 오버레이로 모든 뷰에 오버레이로 추가 할 수 있습니다.
추가 mMyDrawable
로 mMyView
그 오버레이 :
mMyDrawable.setBounds(0, 0, mMyView.getMeasuredWidth(), mMyView.getMeasuredHeight())
mMyView.getOverlay().add(mMyDrawable)
I have tried the awnsers before but this did not work. Now I jsut used a LinearLayout instead of a TextureView, now it is working without any problem. Hope it helps some others who have the same problem. :)
view = (LinearLayout) findViewById(R.id.view); //this is initialized in the constructor
openWindowOnButtonClick();
public void openWindowOnButtonClick()
{
view.setAlpha((float)0.5);
FloatingActionButton fb = (FloatingActionButton) findViewById(R.id.floatingActionButton);
final InputMethodManager keyboard = (InputMethodManager) getSystemService(getBaseContext().INPUT_METHOD_SERVICE);
fb.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// check if the Overlay should be visible. If this value is false, it is not shown -> show it.
if(view.getVisibility() == View.INVISIBLE)
{
view.setVisibility(View.VISIBLE);
keyboard.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
Log.d("Overlay", "Klick");
}
else if(view.getVisibility() == View.VISIBLE)
{
view.setVisibility(View.INVISIBLE);
keyboard.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
참고URL : https://stackoverflow.com/questions/7519160/android-overlay-a-view-ontop-of-everything
'Development Tip' 카테고리의 다른 글
php 문자열 연결, 성능 (0) | 2020.11.04 |
---|---|
Ruby on Rails Routes-get과 match의 차이점 (0) | 2020.11.04 |
Rails에서 파일 업로드 (0) | 2020.11.04 |
내 포함 가드가 재귀 적 포함 및 다중 기호 정의를 방지하지 않는 이유는 무엇입니까? (0) | 2020.11.04 |
angularjs에서 제출시 유효성 검사 오류 메시지 표시 (0) | 2020.11.04 |