如何删除标题栏和LinearLayout的第一个元素之间的黑色空间? [英] How to remove the black space between the title bar and the first element of a LinearLayout?
问题描述
我有一个线性布局,其中第一个元素是imageview标头,第二个元素是gridview.
I have a linearlayout, wich the first element is a imageview header, and the second element is a gridview.
它工作正常,但是我在android标题栏和应用程序标题之间有一个50px(或多或少)的错误黑色空间,这是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
为什么我有那个空间?我发现将其删除的唯一方法是将以下行放置:ll.setPadding(0, -50, 0, 0);
Why i got that space? the only way i find to remove it is to put this line: ll.setPadding(0, -50, 0, 0);
这是完整的代码:
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);
}
快照:
推荐答案
更新:如果您在清单中设置android:theme="@android:style/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的第一个元素之间的黑色空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!