Android Activity 全屏

用了几天的SINA 微博后,感觉他的布局不错,首先是首页全屏图片突出产品预览,感觉不错自己也来试验一把,就一个简单全屏幕实现过程还真是有很多坑,特记录下来希望对大家有帮助!

废话少说,上代码!

public class TestAgent extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
       this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
}

实现全屏其实主要就最后两行代码,但是程序竟然错误,信息如下:

Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:172)
     at android.app.Activity.requestWindowFeature(Activity.java:2719)
意思是 requestFeature 必须在初始化content内容前。我们来看下 API 的说明:

public boolean requestFeature (int featureId)

Since: API Level 1
Enable extended screen features. This must be called before setContentView(). May be called as many times as desired as long as it is before setContentView(). If not called, no extended features will be available. You can not turn off a feature once it is requested. You canot use other title features with FEATURE_CUSTOM_TITLE.
好吧,调整代码调用顺序,把 setContentView() 放到最下面。

怎么样,运行成功了,激动,激动。 我使用的是一个ImageView 来作为首页的图片全屏展示,但是发现Activity全屏了,但是图片没有全部拉伸

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/welcome"/>
</LinearLayout>
其实也和简单在ImageView加上:    android:scaleType="fitXY"    就可以了。 效果图如下:(其实已经看不出来了,看起来就是一张图片)




 





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值