2014-12-27 10 views
7

Volevo impostare il margine su Visualizza programmaticamente. Qui è la mia XML:Android programmato marginalmente il punto di vista

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/llAttendeeList" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:background="#000000"> 

<ListView 
    android:id="@+id/attendeelistview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"  
    android:listSelector="#F6CECE" > 
</ListView> 

</LinearLayout> 

E il metodo, quando il mio tasto onClick per richiamare la vista un'altra finestra:

private void openPopUp() { 
    LayoutInflater layoutInflater = (LayoutInflater) getActivity() 
      .getBaseContext().getSystemService(
        context.LAYOUT_INFLATER_SERVICE); 
    View popupView = layoutInflater.inflate(R.layout.event_attendee_pop, 
      null); 
    llAttendeeList = (LinearLayout) popupView 
      .findViewById(R.id.llAttendeeList); 
    attendeeListView = (ListView) popupView.findViewById(R.id.attendeelistview); 


    LayoutParams params = new LayoutParams(
      LayoutParams.WRAP_CONTENT,  
      LayoutParams.WRAP_CONTENT 
    ); 
    params.setMargins(10, 10, 10, 0); 
    popupView.setLayoutParams(params); 

    final PopupWindow popupWindow = new PopupWindow(popupView, 
      LayoutParams.WRAP_CONTENT, 350); 
    popupWindow.setOutsideTouchable(true); 
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); 

    popupWindow.setTouchInterceptor(new OnTouchListener() { 
     public boolean onTouch(View v, MotionEvent event) { 
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { 
       popupWindow.dismiss(); 
       return true; 
      } 
      return false; 
     } 
    }); 
    popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0); 
    mAdapter = new ListAdapter(getActivity()); 
    attendeeListView.setAdapter(mAdapter); 
} 

ho cercato di impostare il margine al popupView ma senza fortuna. Il margine non c'è. Mi chiedo quale parte la sovrascriva.

Grazie in anticipo.

risposta

5

larghezza e l'altezza Impostare manualmente di PopupWindow:

Display display = getWindowManager().getDefaultDisplay(); 
Point size = new Point(); 
display.getSize(size); 
int width = size.x; 
int height = size.y; 

popupWindow.setWidth(width-10); 
popupWindow.setHeight(height-10); 
+0

Grazie mille! Funziona! – hyperfkcb

+0

@ Denise, felice di aiutarti. –

2

tenta di utilizzare il layout che funzionerà

LinearLayout.LayoutParams params = new LayoutParams 
(

    LayoutParams.WRAP_CONTENT,   
    LayoutParams.WRAP_CONTENT 
); 

params.setMargins(left, top, right, bottom); 
yourbutton.setLayoutParams(params); 

seguire questo tutorial http://www.codota.com/android/classes/android.view.ViewGroup.MarginLayoutParams

+0

l'ho usato. Puoi controllare la domanda che ho postato. – hyperfkcb

+0

Scusa ma hai modificato la tua risposta? – hyperfkcb

+0

prova ad aggiungere LinearLayout.LayoutParams perché dipende da quale layout stai utilizzando fratello .. –

Problemi correlati