Android连载14-适应不同分辨率而编写碎片
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Android连载14-适应不同分辨率而编写碎片,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2667字,纯文字阅读大概需要4分钟。
内容图文
一、编辑布局
1.分别来写两个布局:一个用于平板等大屏幕分辨率的,一个用于手机等小屏幕分辨率的,先写小的,地址:layout/activity_main.xml
< LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android" android:layout_width ="match_parent" android:layout_height ="match_parent" > < fragment android:id ="@+id/news_title_fragment" android:name ="com.example.fragmentbestpractice.NewsTitleFragment" android:layout_width ="match_parent" android:layout_height ="match_parent" /> </ LinearLayout >
然后再layout并列地方写一个大分辨率的布局
地址:layout-sw600dp/activity_main.xml
< LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android" android:layout_width ="match_parent" android:layout_height ="match_parent" > < fragment android:id ="@+id/news_title_fragment" android:name ="com.example.fragmentbestpractice.NewsTitleFragment" android:layout_width ="0dp" android:layout_height ="match_parent" android:layout_weight ="1" /> < FrameLayout android:id ="@+id/news_content_layout" android:layout_width ="0dp" android:layout_height ="match_parent" android:layout_weight ="3" > < fragment android:id ="@+id/news_content_fragment" android:name ="com.example.fragmentbestpractice.NewsContentFragment" android:layout_width ="match_parent" android:layout_height ="match_parent" /> </ FrameLayout > ? </ LinearLayout >
编写了两个界面。
二、修改主活动
package com.example.fragmentbestpractice; ? import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.Window; ? public class MainActivity extends Activity { ? @Override protectedvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); } ? @Override publicboolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); returntrue; } ? @Override publicboolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId(); if (id == R.id.action_settings) { returntrue; } returnsuper.onOptionsItemSelected(item); } }
这样运行我们的APP
连载了很多天android了,前面的东西有些忘了,未来的andorid连载将会专注于复习之前学的。?
三、源码:
1.项目地址
https://github.com/ruigege66/Android/tree/master/FragmentBestPractise
2.CSDN:https://blog.csdn.net/weixin_44630050
3.博客园:https://www.cnblogs.com/ruigege0000/
4.欢迎关注微信公众号:傅里叶变换,个人公众号,仅用于学习交流,后台回复”礼包“,获取大数据学习资料
原文:https://www.cnblogs.com/ruigege0000/p/12984867.html
内容总结
以上是互联网集市为您收集整理的Android连载14-适应不同分辨率而编写碎片全部内容,希望文章能够帮你解决Android连载14-适应不同分辨率而编写碎片所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。