2012-09-05 2 views
0

저는 해결책을 찾기 위해 노력해 왔으며, FrameLayout 또는 RelativeLayout이 사용되는 솔루션 만 찾고 LinearLayout을 사용하고 있습니다.안드로이드 - 화면 중앙에있는 포 그라운드 이미지를 설정하는 방법은 무엇입니까?

내가하고자하는 것은 이미지를 포어 그라운드에 표시하여 페이지에 어떤 것이로드되기 전에 "기다려주십시오"라고 말합니다. 그리고 나는 그 이미지를 중심에 놓으려고 노력하고 있고, 다른 페이지 요소를 바꾸지 않으려 고합니다. 그래서 전 포 그라운드에서 그것을 필요로합니다. 맞습니까?

어떻게하면됩니까?

<ImageView 
    android:id="@+id/please_wait" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/please_wait" 
    android:foregroundGravity="center|fill_horizontal" /> 

하지만 이미지를 중심으로하지 않고 전경에 넣어되지 않은 : 지금은이 있습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 

<include android:id="@+id/header" 
     layout="@layout/header" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent"/>  

<ImageView 
     android:id="@+id/please_wait" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/please_wait" 
     android:foregroundGravity="center|fill_horizontal" 
     /> 

<TextView 
    android:id="@+id/problem_loading_prompt"  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Getting the business(es) you are planning. They are stored in a database that is constantly backed up so you do not lose your work." 
    />   

    <ListView 
    android:id="@android:id/list" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@+id/label" 
     android:textSize="17sp"> 
    </ListView> 

     <Button 
    android:id="@+id/add_problem_ok" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor="@color/light_best_blue" 
    android:text="Plan a New Business" 
    android:layout_marginTop ="15dp"  
    /> 
</LinearLayout> 

감사 :

여기에 전체 XML 파일입니다!

+0

전체 xml 파일에 붙여 넣을 수 있습니다. pls .. –

+0

@ Rahmathullah M Pulikkal 방금 붙여 넣기 - 감사합니다. – Genadinik

+0

로드하는 동안 다른 구성 요소가 숨겨집니다. 권리? –

답변

2

를 호출합니다. 여기 : http://developer.android.com/guide/topics/ui/dialogs.html 당신은 좋은 튜토리얼을 어떻게 대화 상자를 만들 수 있습니다. 뷰어 스피너가 있기 때문에 AlertDialog를 사용자 지정 뷰 또는 ProgressDialog와 함께 사용할 수 있다고 생각합니다.

대화 상자는 xml이 아닌 Java 코드에서 호출하므로 Dialog는 질문에 대한 엄격한 답변이 아니지만 원하는 내용에 가깝다고 생각합니다.

xml에서 실제로 이와 같은 작업을 수행하려는 경우 FrameLayout을 사용해야한다고 생각합니다. FrameLayout은 이와 같은 작업을 수행하도록 설계 되었기 때문에 사용해야합니다. 또는 RelativeLayout을 사용해 볼 수도 있습니다.

편집 :

Dialog dialog = new Dialog(context); 
dialog.setContentView(R.layout.custom); 
dialog.show(); //this will show dialog 
dialog.dismiss(); //now dialog will disapear 

그리고 여기 당신이 XML 파일 이름을 지정한있는 Custom.xml : : 물론

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

<ImageView 
    android:id="@+id/please_wait" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/please_wait"/> 

</RelativeLayout> 

당신이 다른 레이아웃을 사용할 수 있습니다 여기에 귀하의 이미지에 AlertDialog를 생성하기위한 샘플 코드는 또한.

1

왜 이런 일하려고하지 말아 : 당신이 지금까지 당신이 한 전체 레이아웃을 유지할 수 있습니다

<RelativeLayout> 

    <LinearLayout> 
     <Your existing stuff /> 
    </LinearLayout> 

    <ImageView 
     android:centerInParent="true" /> 

</RelativeLayout> 

이 방법을, 그리고 RelativeLayout 멋지게 모든 것을 상단에 이미지를 넣어 것입니다. 당신은 더 이상 ImageView 필요하지 않으면, 그냥 내가 가장 좋은 방법은 메시지는 대화 상자를 만들 수있다 "기다려주십시오"표시 할 수 있다고 생각

imageView.setVisibility(View.INVISIBLE /*or View.GONE */); 
+0

상대 레이아웃에 있어야합니까? 내 것은 선형 레이아웃을 사용하고 있으며 내가 좋아하는 제안은 불행히도 어떤 이유로 선형 레이아웃에서 작동하지 않습니다. 어떤 생각이 가장 좋은 접근 방법입니까? 상대 레이아웃으로 전환해야합니까? – Genadinik

+0

안녕하세요.RelativeLayout은 물건을 서로 위에 놓을 수 있기 때문에 사람들에게 추천합니다. LinearLayout은 자식을 서로 위에 놓지 않습니다. 예제를 작성하려고 했으므로 기존 레이아웃을 다시 작성하지 않아도됩니다. LinearLayout에 기존 애플리케이션 레이아웃을 래핑하고 그 후에 ImageView를 추가하고 모든 것을 RelativeLayout에 넣기 만하면됩니다. –

1

시도해 보셨습니까?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:gravity="center" >    <--- like this 

<ImageView 
    android:id="@+id/please_wait" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:foregroundGravity="center|fill_horizontal" 
    android:src="@drawable/arrow" /> 

</LinearLayout> 

저에게 적합합니다.

+0

android : gravity = "center"로 이것을 시도했지만 화면에 이상한 효과가 있었지만 주변을 약간 옮겼지만 여전히 이미지를 전경에 두지 않았습니다. – Genadinik

관련 문제