2013-06-26 2 views
0

런타임시 전체 화면 너비의 절반의 절반 크기로 imagview 및 textview 크기를 설정하고 싶습니다. 하지만 잘 작동하지 않습니다. 이미지 뷰는 총 화면 크기의 절반을 설정 한 후에 작게 표시됩니다.레이아웃보기가 주어진 크기에 맞지 않습니다.

이 문제를 해결하는 데 도움을주십시오. 지난 1 일부터 시도했지만 문제를 인식하지 못했습니다.

미리 감사드립니다.

enter image description here

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

<RelativeLayout 
    android:id="@+id/relativeLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/light_white" > 

    <TextView 
     android:id="@+id/noticeHeading" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="15dip" 
     android:layout_marginTop="25dip" 
     android:textColor="@color/black" 
     android:textSize="18dip" /> 

    <TextView 
     android:id="@+id/noticeContent" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@id/noticeHeading" 
     android:layout_below="@id/noticeHeading" 
     android:layout_marginTop="20dp" 
     android:textColor="@color/black" 
     android:textSize="16dip" /> 

    <ImageView 
     android:id="@+id/noticeImageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/noticeHeading" 
     android:layout_marginLeft="20dip" 
     android:layout_marginRight="20dip" 
     android:layout_toRightOf="@id/noticeHeading" /> 
</RelativeLayout> 
</ScrollView> 

코드 :

View rootView = inflater.inflate(res, container, false); 
noticeHeaderTextView = (TextView)rootView.findViewById(R.id.noticeHeading); 

noticeContentTextView = (TextView)rootView.findViewById(R.id.noticeContent); 

noticeImageView = (ImageView)rootView.findViewById(R.id.noticeImageView); 

DisplayMetrics metrics = getResources().getDisplayMetrics(); 
int width = metrics.widthPixels; 


noticeImageView.getLayoutParams().width = width/2; 
noticeHeaderTextView.getLayoutParams().width = width/2; 
noticeContentTextView.getLayoutParams().width = width/2; 
+0

변경된 뷰에서'requestLayout()'을 호출하십시오. (아마도'rootView'를 호출하는 것조차도 충분합니다) –

+0

이것을 시도했지만 화면의 크기에 따라 방향이 바뀝니다. –

+0

이미지에 일정한 너비를 주려고합니다. –

답변

0

는 선형 레이아웃을 사용하여 상대 레이아웃 0.5 layout_weight를 설정 넣어보다, 그것으로 당신의 상대 레이아웃을 넣어. textview와 imageview에서 모두 match_parent를 높이로 적용하십시오. 희망이 있습니다. 이것이 xml에서 작동하면 LayoutPerameter 클래스를 통해 동적으로 동일하게 수행 할 수 있습니다.

+0

imageview align을 headertextview에 맞추지 만 그 위로 정렬하지 않아야합니다. 왜 그 이유를 도와주세요 –

+0

크기 나 레이아웃을 수동으로 변경 한 후에는 각 뷰에서 무효화를 호출해야합니다. 왜 팽창 시키는가, findViewById를 사용하여 참조를 직접 첨부 할 수 있습니까? –

+0

잘 맞지 만, xml 레이아웃에서 언급 한 headertextview와 꼭 맞지 않습니다. –

관련 문제