2014-12-27 25 views
7

Tôi muốn đặt lề thành Xem theo chương trình. Dưới đây là XML của tôi:Biên độ xem thiết lập Android theo chương trình

<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> 

Và phương pháp khi nút của tôi onClick để gọi ra xem cửa sổ bật lên cửa sổ:

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); 
} 

Tôi cố gắng để thiết lập lề cho popupView nhưng không có may mắn. Lề không có ở đó. Tôi tự hỏi phần nào ghi đè lên nó.

Xin cảm ơn trước.

Trả lời

5

thủ thiết lập chiều rộng và chiều cao của 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

Cảm ơn rất nhiều! Nó hoạt động! – hyperfkcb

+0

@ Denise, Vui mừng được giúp bạn. –

2

cố gắng sử dụng bố cục nó sẽ làm việc

LinearLayout.LayoutParams params = new LayoutParams 
(

    LayoutParams.WRAP_CONTENT,   
    LayoutParams.WRAP_CONTENT 
); 

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

theo hướng dẫn này http://www.codota.com/android/classes/android.view.ViewGroup.MarginLayoutParams

+0

tôi đã sử dụng nó. Bạn có thể kiểm tra câu hỏi tôi đã đăng. – hyperfkcb

+0

Xin lỗi, nhưng bạn đã sửa câu trả lời chưa? – hyperfkcb

+0

cố gắng thêm LinearLayout.LayoutParams bởi vì nó phụ thuộc vào bố trí bạn đang sử dụng anh trai .. –

Các vấn đề liên quan