透明活动左边缘

时间:2015-04-15 09:49:39

标签: android android-layout

我的应用程序中存在透明活动,我想为此活动提供左,右,上边距。为此我使用 WindowManager.LayoutParams 。但在那里,我无法一次向右,左,右倾。只有两个参数x和y。如果我想设置左,右和顶部,那么我需要做什么。

代码: -

public class SelectedRecipient extends Activity {
private Context context;
private WindowManager.LayoutParams wmParams=null;
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);



    System.out.println("*** SelectedRecipient ***");

    context = SelectedRecipient.this;

    WindowManager.LayoutParams wmParams = this.getWindow().getAttributes();

    wmParams.gravity = Gravity.TOP | Gravity.LEFT;
    wmParams.x = 50; // x position
    wmParams.y = 40; // y position

    ArrayList<String> aListNoOfSelection = new ArrayList<String>();
    aListNoOfSelection.add("Vinit");
    aListNoOfSelection.add("Vikash");
    aListNoOfSelection.add("Jonson");
    aListNoOfSelection.add("Nikolesh");
    ArrayAdapter<String> aAdapterNoOfSelection = new NoOfSelectionAdapter(context, 0, aListNoOfSelection);

    listView = new ListView(context);

    listView.setAdapter(aAdapterNoOfSelection);
    setContentView(listView);
}
}

我也试过这个(不是工作): -

LayoutParams layoutParams = new LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(50, 0, 50, 0);
listView.setLayoutParams(layoutParams);

enter image description here

1 个答案:

答案 0 :(得分:0)

您可能想要使用上面回答的对话框主题,如果是这样的话...... 将android:theme="@android:style/Theme.Dialog"放入AndroidManifest.xml

或在setTheme(android.R.style.Theme_Dialog);

中致电setContentView();之前致电:onCreate()

如果没有,你可以使用类似的东西:

ViewGroup.MarginLayoutParams wmParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
wmParams.setMargins((int left),(int top),(int right),(int bottom));

wmParams.bottomMarginwmParams.leftMarginwmParams.rightMarginwmParams.topMargin