2017-02-21 1 views
1

[! [이미지 설명을 여기에 입력하십시오.] [1]] [1] 안드로이드 개발에 안드로이드에 대한 새로운 브랜드이고 레이아웃을 빌드하기 위해 xml을 가지고 놀고 있습니다. 안녕 우분투를 인쇄하고 이미지를 삽입하기 위해 다음과 같은 코드를 작성했습니다. 그러나 Image는 원치 않는 위/아래 패딩이나 마진 (그것이 무엇인지 불확실합니다)이 이상하게 보입니다. 아무도 나를 제거하는 것을 도와주세요. 여기ImageView에서 원하지 않는 여백 또는 여백

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:background="@color/colorAccent" 
    android:orientation="vertical" 
    android:padding="10dp" 
    > 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="8dp" 
     android:layout_margin="8dp" 
     android:text="Hello Ubuntu (16.06LTS)" 
     android:background="@color/colorPrimary"/> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dp" 
     android:src="@mipmap/Ubuntu" 
     android:layout_margin="0dp" 

     /> 
    </LinearLayout> 

스크린 샷 (오른쪽 preiew 참조) : https://i.stack.imgur.com/j9NlT.png

+0

'우분투'라는 이름의 이미지를 확인하십시오. 여분의 공간이 있습니까? – Piyush

+0

당신이 실제로 어떻게 보이는지에 대한 이미지를 추가 할 수 및 당신이 스크린 샷을 업로드 이미지 뷰 .centerInside –

+0

PLZ 수하는 방법을 –

답변

0

당신은 사용해야 android:scaleType (documentation 참조) 여기 내 코드입니다. 이렇게하면 이미지의 크기가 정확하게 표시되지 않는 경우 반응하는 방법을보기에 알릴 수 있습니다.

+0

나는 이미 그것을 시도했지만 실시간으로 아무것도 – ShivamProgramer

+0

당신이 셀프 위해 노력했다 일어나지 않는다 '센터 자르기'? 그리고 또한 귀하의 스크린 샷에 따르면, 그것은 te 이미지가 대수롭지 않은 것처럼 보입니다. 어쩌면 이미지 뷰에 배경색을 설정하여 이미지가 모든 imggr 뷰를 채우고 있는지 확인할 수 있습니다. – sonic

+0

예 centreCrop을 사용해 보았지만 제대로 작동하지 못했습니다 – ShivamProgramer

0

이미지 뷰 위에 여백이 있지만 이미지 뷰의 일부가 아닙니다. 실제로는 이미지 뷰 위에있는 텍스트 뷰에 적용된 여백 때문입니다. 다음 코드를 수행 할 수 있습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="match_parent" 
android:layout_width="match_parent" 
android:background="#00ffff" 
android:orientation="vertical" 
android:padding="10dp" 
> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginTop="8dp" 
    android:text="Hello Ubuntu (16.06LTS)" 
    android:background="#000000"/> 

<ImageView 
    android:layout_width="371dp" 
    android:layout_height="match_parent" 
    android:padding="0dp" 
    android:background="#ff0000" 
    android:layout_margin="0dp" 
    /> 

편집 - 당신의 위의 코드에서 , 당신은 뷰의 모든 측면에 여백을 적용했습니다. (android:layout_margin="8dp ") 이는 이미지 뷰의 상단 여백으로 나타납니다 하단 하나를 포함하여 모든 4 개면에서 뷰에 마진을 제공합니다.

을 따라서, 당신이 필요가있는 무엇을하여보기 측에 마진을 적용하는 것입니다 android:layout_margin="8dp"

android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:layout_marginUpper="8dp"

편집 2를 변경하여 사이드 -. 당신이 부모 (루트) 용기에 0 패딩 0 마진이 있는지 확인

+0

변경된 내용과 이유가 무엇인지 자세히 설명해주세요 – ShivamProgramer

+0

해당 업무가 수행되지 않았습니다. – ShivamProgramer

0

당신은 나를 위해 작동

android:adjustViewBounds="true",

시도 할 수 있습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:background="@color/colorAccent" 
    android:orientation="vertical" 
    android:padding="10dp" 
    > 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="8dp" 
     android:layout_margin="8dp" 
     android:text="Hello Ubuntu (16.06LTS)" 
     android:background="@color/colorPrimary"/> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/asd" 
     android:layout_margin="0dp" 
     android:adjustViewBounds="true" 

     /> 
</LinearLayout> 
+0

해결 되었습니까? –

관련 문제