2012-11-10 3 views
13

fill_parent을 사용하는 경우 maxWidth은 아무 효과가 없습니다.maxWidth가 fill_parent와 함께 작동하지 않습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 
    <LinearLayout android:layout_width="fill_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 
     <EditText android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:maxWidth="50dip"/> 
    </LinearLayout>  
</LinearLayout> 

답변

23

속성 maxWidthmatch_parent는 폭에 영향을주지 않는다 (또는 사용되지는 fill_parent)들은 상호 배타적이다. wrap_content을 사용해야합니다. 당신은 다른 화면에 다른 레이아웃을 사용하여 동일한 효과를 얻을 수

<?xml version="1.0" encoding="utf-8"?> 
<EditText xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:maxWidth="50dip"/> 
+2

감사합니다. 내 EditText를 화면의 모든 너비에 채우지 만 nore 500dip을 채우지 않으려면 어떻게해야합니까? 예를 들어, 일부 화면은 해상도가 <500입니다. –

+11

이것은 바보 같지만 작동합니다 :'minWidth'를 추가하고 "min"과 "max"를 모두 '500dp'로 설정하십시오. – Sam

+1

@Sam - 나에게 효과가있는 것 같지 않은데, editText는 여전히 여백을 제외한 전체 화면을 채 웁니다. 당신은 정교 할 수 있습니까? – katzenhut

3

:

또한 단 하나의 아이가 어떤 레이아웃은 아마 예를 들어 당신이 당신에게 현재의 레이아웃을 간소화 할 수 있습니다, 제거 할 수 있습니다. EditText이 480dp 이하의 너비를 채우라고합니다. 다음과 같이 레이아웃을 Difine :

레이아웃/my_layout.xml :

<?xml version="1.0" encoding="utf-8"?> 
<EditText xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

레이아웃 w480dp/my_layout.xml :

<?xml version="1.0" encoding="utf-8"?> 
<EditText xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="480dp" 
      android:layout_height="wrap_content"/> 
(여기에 규정 자로 당신에게 최대 너비를 선택)
관련 문제