2016-06-14 4 views
-1

여기 고정 크기 ImageView에 대해서는 묻지 않습니다. 정적으로 내가 좋아하는 의미 :Android - XML로 정적 ImageView를 만드는 방법?

private static ImageView imageView = new ImageView(context); 

지금 나는이 프로그램을 할 수있는 방법이지만, XML에서 정적 ImageView를 선언 할 수있는 방법이 있다는 것을 알고?

사실 내 레이아웃의 일부 (이 경우 ImageView)를 응용 프로그램 전체에서 공통으로 사용하고자합니다.

+0

내 ImageView는 어떻게 정적으로 만들까요? –

+0

죄송합니다. 질문에 대한 오해를했습니다. imageView로 레이아웃을 만들고 다른 xml 파일에서''을 사용하여 해당 레이아웃을 다시 사용하십시오. – SripadRaj

답변

0

1.Create 그것을 또는 활동

0

에서 팽창 파일 common_image_view.xml 만들기 이미지 뷰 2.then의 사용과 레이아웃 파일

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ImageView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/image” /> 
</FrameLayout> 

다른 레이아웃이 사용 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center_horizontal"> 

    <include layout="@layout/common_image_view"/> 

    <TextView android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/hello" 
       android:padding="10dp" /> 

</LinearLayout> 
0

문제에 따라 응용 프로그램 전체에서 사용할 수있는 ImageView를 만들고 싶습니다. ation. 당신은

지금이 레이아웃 직접 활동에 팽창 할 수있는 레이아웃

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/imagelayout"> 

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

만들기 ...이 같은 작업을 수행 할 수 있습니다. 또는 다른 레이아웃 xml처럼 사용할 수도 있습니다 ..

<include layout="@layout/imagelayout" /> 

희망이 도움이 될 것입니다.

관련 문제