2011-01-21 9 views
5

이것은 365로 높이를 코딩했기 때문에 에뮬레이터에서는 잘 작동하지만 기기에서는 작동하지 않습니다.안드로이드에서 동적으로 상대 레이아웃의 높이를 설정하는 방법

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
<TabHost android:id="@+id/tab_host" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <TabWidget android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:id="@android:id/tabs" 
     android:layout_gravity="bottom"/> 
     <FrameLayout android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" android:layout_height="fill_parent"> 
      <RelativeLayout android:id="@+id/first_tab" 
       android:orientation="vertical" android:layout_width="fill_parent" 
       android:layout_height="365px"> 
       <WebView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/webview" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"/> 
        <ImageView 
         android:id="@+id/widget31" 
         android:layout_width="fill_parent" 
         android:layout_height="49px" 
         android:layout_x="0px" 
         android:layout_y="0px" 
         android:background="#39000000" 
         android:layout_alignParentBottom="true"> 
        </ImageView> 
        <ImageButton 
         android:id="@+id/btnFB" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/fb" 
         android:background="#00000000" 
         android:layout_alignRight="@+id/widget31" 
         android:layout_alignParentBottom="true"> 
        </ImageButton> 
        <TextView 
         android:id="@+id/myTextView1" 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" 
         android:text="Share" 
         android:textColor="#111111" 
         android:textSize="14pt" 
         android:paddingBottom="5px" 
         android:layout_alignLeft="@+id/widget31" 
         android:layout_alignParentBottom="true"/> 
         <ImageButton 
          android:id="@+id/btnTwitter" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:src="@drawable/twitter" 
          android:visibility="invisible" 
          android:background="#00000000" 
          android:layout_alignRight="@+id/widget31" 
          android:layout_alignParentBottom="true"> 
         </ImageButton> 
      <!-- Replace TextView with your layout content for this tab --> 
      </RelativeLayout> 
      <LinearLayout android:id="@+id/second_tab" 
       android:orientation="vertical" android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
       <ScrollView 
        android:id="@+id/ScrollView01" 
        android:layout_height="365px" 
        android:layout_width="fill_parent"> 
        <WebView xmlns:android="http://schemas.android.com/apk/res/android" 
         android:id="@+id/webviewForRSS" 
         android:layout_width="fill_parent" 
         android:layout_height="365px" 
         android:background="#98012E"/> 
       </ScrollView> 
      <!-- Replace TextView with your layout content for this tab --> 
      </LinearLayout> 
      <LinearLayout android:id="@+id/edit_item_text_tab" 
       android:orientation="vertical" android:layout_width="fill_parent" 
       android:layout_height="fill_parent"/> 
      </FrameLayout> 
    </TabHost> 
</RelativeLayout> 

감사합니다.

답변

15

당신은 -----

첫째,

getLayoutParams().height= x; 
requestLayout(); or invalidate(); 

둘째,

first_tab.setHeight(int pixels); 

방식의 누군가를 사용해보십시오 다른 방법을 통해 동적으로 레이아웃 높이를 변경할 수 있습니다. ......

6

px을 사용하지 말고 대신 dp을 사용하십시오.

android:layout_height="365dp" 

은 읽기 here, 알 밀도 독립적 픽셀 (DP) 더 나은 되세요. 다른 화면에 UI의 적절한 표시를 보장하는 방법으로, 당신의 응용 프로그램의 UI는 매우 권장 정의 DP 단위를 사용

.

관련 문제