[英]How to remove the black space between the title bar and the first element of a LinearLayout?
我有一個線性布局,第一個元素是一個圖像視圖標題,第二個元素是一個網格視圖。
它工作正常,但我在 android 標題欄和應用程序的標題之間有一個 50px(或多或少)的錯誤黑色空間,這是線性布局的第一個元素
為什么我有那個空間? 我發現刪除它的唯一方法是放置這一行: 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);
}
快照:
如果你不使用標題欄,你總是可以擺脫它:
http://elliotth.blogspot.com/2009/07/removing-title-bar-from-your-android.html
更新:如果您在 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);
}
在清單中的活動標簽中使用它可以解決您的問題
android:theme="@android:style/Theme.NoTitleBar"
對於全屏,您應該使用
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.