欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新

Android连载14-适应不同分辨率而编写碎片,

来源: 开发者 投稿于  被查看 7854 次 评论:236

Android连载14-适应不同分辨率而编写碎片,


一、编辑布局

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

  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_main);

  }

​

  @Override

  public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.

    getMenuInflater().inflate(R.menu.main, menu);

    return true;

  }

​

  @Override

  public boolean 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) {

      return true;

    }

    return super.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.欢迎关注微信公众号:傅里叶变换,个人公众号,仅用于学习交流,后台回复”礼包“,获取大数据学习资料

 

 

相关文章

    暂无相关文章

用户评论