2011-08-26 16 views
6

Sono nuovo di Android.come modificare l'altezza e la larghezza del layout del fotogramma in modo programmatico?

affronto un problema che è che io sono l'aggiunta di layout cornice alla mia domanda il codice è

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <FrameLayout android:id="@+id/frameLayout1"> 
     <LinearLayout 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout1" 
     android:layout_width="fill_parent"> 
     </LinearLayout> 
    </FrameLayout> 
</LinearLayout> 

Il mio problema è che voglio cambiare l'altezza di layout telaio in diversi orientamenti dello schermo

il codice di esempio è

wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE); 

      getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 

      Log.v("height","height"+wm.getDefaultDisplay().getHeight()); 

      if(wm.getDefaultDisplay().getHeight() <= 427) 
      { 
       Log.v("height","111"); 


((FrameLayout)findViewById(R.id.frameLayout1)).setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); 
     } 
     else 
     { 
      ((FrameLayout)findViewById(R.id.frameLayout1)).setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); 
     } 

Ma dà forza vicino,

se qualcuno ha un'idea, per favore aiutatemi.

Grazie in anticipo.

risposta

0

Un modo è creare una vista personalizzata e sovrascrivere le funzioni onLayout e onMeasure. Nella funzione onLayout puoi sovrascrivere la larghezza e l'altezza. Vedere l'esempio LabelView.java class here.

3

Devi usare LinearLayout.LayoutParams (int width, altezza int, float peso)

FrameLayout frameLayout = new FrameLayout(context); 
LinearLayout.LayoutParams layPra = new LinearLayout.LayoutParams(width,height,mWeight); 
layPra .gravity = Gravity.CENTER | Gravity.BOTTOM; 
frameLayout .setLayoutParams(layPra); 
Problemi correlati