2016-08-04 3 views
3

내 xml 파일에서 각 작은 원 (ImageView)을 선형보기 및 layout_weights가있는 화면의 25 % 크기로 설정했습니다.
여기 는 (그것을보고 생각하는 방법) 내 휴대 전화에서 스크린 샷 : 그것은 화면의 25 %로 크기를 변경하지 않습니다선형 레이아웃에서 layout_weight를 수정하는 방법은 무엇입니까?

내 태블릿

enter image description here

이는 모습입니다 :

enter image description here

내 코드 셋은 LinearLayouts의 1
다음 중 0.25의 가중치를 각각 포함 ImageViews를 구성하는 코드는 다음과 같습니다

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    xmlns:ads="http://schemas.android.com/apk/res-auto"> 
    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/imageView12" 
     android:src="@drawable/circle_big" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" /> 

    <LinearLayout 
     android:id="@+id/wrapper" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1.0" 
     android:layout_centerVertical="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     > 

     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.03125"> 
     </FrameLayout> 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.25" 
      android:id="@+id/imageView12" 
      android:src="@drawable/circle_white" 
      android:onClick="changeToScreenSelectLayout" 
      android:scaleType="fitCenter" 
      android:adjustViewBounds="true" 
      /> 
     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.09375"> 
     </FrameLayout> 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.25" 
      android:id="@+id/imageView12" 
      android:src="@drawable/circle_white" 
      android:onClick="changeToScreenSelectLayout" 
      android:scaleType="fitCenter" 
      android:adjustViewBounds="true" 
      /> 
     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.09375"> 
     </FrameLayout> 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.25" 
      android:id="@+id/imageView12" 
      android:src="@drawable/circle_white" 
      android:onClick="changeToScreenSelectLayout" 
      android:scaleType="fitCenter" 
      android:adjustViewBounds="true" 
      /> 

     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.03125"> 

     </FrameLayout> 


    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/wrapper" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1.0" 
     android:layout_centerVertical="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:rotation = "120" 
     > 

     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.03125"> 
     </FrameLayout> 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.25" 
      android:id="@+id/imageView12" 
      android:src="@drawable/circle_white" 
      android:onClick="changeToScreenSelectLayout" 
      android:scaleType="fitCenter" 
      android:adjustViewBounds="true" 
      /> 
     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.4375"> 
     </FrameLayout> 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.25" 
      android:id="@+id/imageView12" 
      android:src="@drawable/circle_white" 
      android:onClick="changeToScreenSelectLayout" 
      android:scaleType="fitCenter" 
      android:adjustViewBounds="true" 
      /> 

     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.03125"> 

     </FrameLayout> 


    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/wrapper" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1.0" 
     android:layout_centerVertical="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:rotation = "60" 
     > 

     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.03125"> 
     </FrameLayout> 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.25" 
      android:id="@+id/imageView12" 
      android:src="@drawable/circle_white" 
      android:onClick="changeToScreenSelectLayout" 
      android:scaleType="fitCenter" 
      android:adjustViewBounds="true" 
      /> 
     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.4375"> 
     </FrameLayout> 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.25" 
      android:id="@+id/imageView12" 
      android:src="@drawable/circle_white" 
      android:onClick="changeToScreenSelectLayout" 
      android:scaleType="fitCenter" 
      android:adjustViewBounds="true" 
      /> 

     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.03125"> 

     </FrameLayout> 


    </LinearLayout> 

</RelativeLayout> 
+0

PercentRelativeLayout을 사용하면 도움이 될 수 있습니다. –

+0

알고있는 한, 레이아웃 가중치는 정수이어야합니다. –

+0

@ cricket_007 ** wrong **. 부동 소수점 값이 될 수 있습니다. –

답변

1

circle_white로 png 파일을 사용할 수 없습니다. 올바른 android : scaleType을 선택하면 기술적으로이 작업을 수행 할 수 있지만 몹시 앨리어싱 된 렌더링이 발생합니다.

먼저 (각 리소스 버킷에서) 기존 PNG를 삭제할 것이므로 사용할 수 없습니다. 그런 다음 "circle_white.xml"이라는 드로어 블에 새 파일을 만듭니다. 이것을 넣으면 내재 크기가없는 원이 그려집니다. I.E. 그것은 당신이 렌더링 한 것을 채울 것입니다.

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval"> 
    <solid 
     android:color="#fff"/> 
</shape> 

그리고이 새로운 @ 드로어 블/circle_white로 설정 배경과 HeightMatchesWidthView에 circle_white의 SRC와 이미지 뷰의 사용에서 변경합니다. 보기 높이가 아래의보기 확장에서 수행 한 너비와 일치하는지 확인해야합니다. 단지 어딘가에 새로운 클래스를 만들고이 붙여 넣기이를 사용하십시오. XML로 대신 이미지 뷰를 가지는하여 참조하는 com.whatever 당신이에 넣고 어떤 패키지 com.whatever.HeightMatchesWidthView을한다.

public class HeightMatchesWidthView extends View { 
    public HeightMatchesWidthView(final Context context) { 
     super(context); 
    } 

    public HeightMatchesWidthView(final Context context, final AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public HeightMatchesWidthView(final Context context, final AttributeSet attrs, final int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    @Override 
    protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { 
     int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec); 
     setMeasuredDimension(width, width); 
    } 

    @Override 
    protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) { 
     super.onSizeChanged(w, w, oldw, oldh); 
    } 
} 

을 대신 HeightMatchesWidthView의 대신에 PercentRelativeLayout을 사용하여 사각형을 강제로 사용하고 올바른 크기로 View를 확장하지 않고 사각형을 강제로지지하도록 추가 할 수 있습니다.

+0

흰색 동그라미입니다 사진에서 – sazzy4o

+0

그래서 실제 PNG 파일? –

+0

예 ldpi에서 xxhdpi까지의 png 파일입니다. – sazzy4o

관련 문제