问题描述
我有一个的LinearLayout,至极的第一个元素是一个ImageView的标题,第二个元素是一个gridview。
I have a linearlayout, wich the first element is a imageview header, and the second element is a gridview.
它工作正常,但我有50像素的erroneal黑色空间(或多或少)Android的丝毫不差吧和应用程序的报头之间,至极是的LinearLayout的第一要素
It works fine, but i have a erroneal black space of 50px (more or less) between the android tittle bar and the header of the app, wich is the first element of the linearlayout
WHI我得到的空间呢?我发现删除它的唯一方法就是把这个行: ll.setPadding(0,-50,0,0);
Whi i got that space? the only way i find to remove it is to put this line: ll.setPadding(0, -50, 0, 0);
这是全code:
public class MainGrid extends Activity {
private GridView myGridView;
private ImageAdapter myImageAdapter;
private ImageView header;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//turn off the window's title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//fullscreen
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setGravity(Gravity.CENTER);
//ll.setPadding(0, -50, 0, 0);
header = new ImageView(getApplicationContext());
header.setImageResource(R.drawable.header_acc);
myGridView = new GridView(this);
myImageAdapter=new ImageAdapter(this);
myGridView.setAdapter(myImageAdapter);
ll.addView(header);
ll.addView(myGridView);
setContentView(ll);
}
快照:
推荐答案
更新:这应该工作,如果你设置就好了安卓主题=@安卓风格/ Theme.NoTitleBar.Fullscreen
中的清单。
Update: This should work just fine if you set android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
in the Manifest.
public class MainGrid extends Activity {
private GridView myGridView;
private ImageAdapter myImageAdapter;
private ImageView header;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setGravity(Gravity.TOP); // SET THIS TO TOP
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
ll.setLayoutParams(lp);
// I'VE ADDED LAYOUTPARAMS TOO
header = new ImageView(getApplicationContext());
header.setImageResource(R.drawable.header_acc);
myGridView = new GridView(this);
myImageAdapter=new ImageAdapter(this);
myGridView.setAdapter(myImageAdapter);
ll.addView(header);
ll.addView(myGridView);
setContentView(ll);
}
这篇关于如何删除丝毫不差的酒吧和LinearLayout中的第一个元素之间的黑色空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!