我有一个linearlayout,第一个元素是imageview标题,第二个元素是gridview。
它工作正常,但我在android tittle bar和app的标题之间有一个50px(或多或少)的错误黑色空间,这是linearlayout的第一个元素
为什么我有这个空间?我找到删除它的唯一方法是将此行: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);
}
快照:
答案 0 :(得分:1)
如果你没有使用标题栏,你可以随时摆脱它:
http://elliotth.blogspot.com/2009/07/removing-title-bar-from-your-android.html
答案 1 :(得分:1)
更新:如果你在Manifest中设置android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
,这应该可以正常工作。
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);
}
答案 2 :(得分:1)
在清单中使用此for活动标记可以解决您的问题
android:theme="@android:style/Theme.NoTitleBar"
对于全屏,您应该使用
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"