2017-11-09 8 views
0

아래는 내가 컨텐츠 영역에서 배경 이미지를 표시 할 MainActivity어떻게

|Top Navigation Bar 
|Content Area 
|Bottom Navigation Bar 

내 화면 디자인 안드로이드 태블릿 및 세로 모드에서 배경 이미지로 표시 할 이미지의 크기를 조절합니다. 전체 내용 영역을 채우는

아래의 서버에서 배경 이미지를 얻고 있습니다. 장치가 전화 또는 태블릿 인 경우 JSocket 응답은 배경 이미지를 표시하기 위해 phonePortrait 또는 tabletPortrait 이미지를 선택했습니다. 가로 사용 tabletLandscape 이미지. 이 응답은 Android 및 IOS 앱에서 모두 사용됩니다.

{ 
meta: { 
    timeToCache: 5 
}, 
body: { 
    .... 
    title: "LIVE this week", 
    description: "NBA", 
    phonePortrait: "https://xyx.com.au/home-nba-r1.jpg", 
    tabletPortrait: "https://xyx.com.au//home-nba-r2.jpg", 
    tabletLandscape: "https://xyx.com.au/home-nba-r3.jpg", 
    phoneSmallPortrait: "https://xyx.com.au/home-nba-r4.jpg", 
    .... 
} 
} 

나는

Picasso.with(getContext()) 
        .load(imageUrl) 
        .fit() 
        .into(back_img); 

레이아웃 파일

<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/home_template_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    tools:layout_editor_absoluteX="0dp" 
    tools:layout_editor_absoluteY="89dp"> 
    <ImageView 
     android:id="@+id/back_img" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:background="@drawable/loginbg" 
     android:contentDescription="@string/app_description" 
     android:layout_marginLeft="0dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginRight="0dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="0dp" 
     app:layout_constraintTop_toTopOf="parent" 
     android:adjustViewBounds="true" 
     android:layout_marginTop="0dp"/> 
.... 

</android.support.constraint.ConstraintLayout> 

그러나 문제는 이미지가 제대로 표시되지 않는 backroind의 이미지 뷰에 (이미지 스트레칭 이미지를로드하거나 절단하는 피카소 라이브러리를 사용 상단 부분), 모든 안드로이드 화면 크기에 대해 이미지의 가로 세로 비율을 유지하고 배경 이미지로 표시하는 가장 좋은 방법은 무엇입니까

a) 세로 모드의 경우 mdpi/hdpi/xhpdi/xxhdpi에 대해 여러 이미지를 도입해야합니까, 그렇다면 가로 모드의 경우 이미지 크기가 무엇이되어야합니까?

B) 나는 아래의 코드를 시도했지만 여전히 이미지가 제대로 표시되지 않는) 가로 모드

C에서 작동하는 모든 인물 모드 및 단일 이미지에서 작동하는 하나의 이미지를 사용할 수있는 다른 방법이 사용

/* DisplayMetrics displayMetrics = new DisplayMetrics(); 


getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 
     int screenHeight = displayMetrics.heightPixels; 
     int screenWidth = displayMetrics.widthPixels; 

     int toolBarHeight = getActivity().findViewById(R.id.toolbar).getHeight(); 
     int bottomBarHeight = getActivity().findViewById(R.id.tabs).getHeight(); 

     int viewPortHeight = screenHeight - (toolBarHeight + bottomBarHeight); 

     Picasso 
       .with(getContext()) 
       .load(imageUrl) 
       //.resize(screenWidth,viewPortHeight) // resizes the image to these dimensions (in pixel) 
       .fit() 
       .centerInside() 
       .into(parent_home_template_back_img);*/ 

답변

1

보십시오 : 당신의 ImageView

에서

android:scaleType="fitXY" 

ImageView.ScaleType 더보기

+0

피카소 콜에서 무엇인가를 변경해야합니까? – Sam

+0

@ Sam 당신이 변경하지 않아도된다고 생각합니다 –

+0

scaleType- "fitxy"추가, 행운을 불어 넣으십시오, 정지 이미지가 늘어납니다 – Sam