gpt4 book ai didi

android - 如何删除标题栏和 LinearLayout 的第一个元素之间的黑色空间?

转载 作者:行者123 更新时间:2023-11-29 18:16:44 25 4
gpt4 key购买 nike

我有一个线性布局,第一个元素是 ImageView 标题,第二个元素是 GridView 。

它工作正常,但我在 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);
}

快照:

enter image description here

最佳答案

更新:如果您在 list 中设置 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 - 如何删除标题栏和 LinearLayout 的第一个元素之间的黑色空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7710915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com