64.Mutiple Screen Support

First ,we need import new Image,Using Android Drawable Importer plugin already available in android studio.

Second , we need creat fragment_image.xml layout file with root element LinearLayout.

property android:cropToPadding = "false"今天捣腾ImageView的时候发现padding属性竟然不起作用,折腾一番后才知道原来跟我设置scaletype为centerCrop有关,要想两者同时作用,只需加上android:cropToPadding="true"即可。

Third , Creat class to inflate fragment_image

public class ImageFragment extends Fragment{

  public ImageFragment(){

  }

  @Nullable

  @Override

  public View onCreatView(LayoutInflate inflate,@Nullable ViewGroup container,@Nullable Bundle savedInstanceState){

    return inflater.inflate(R.layout.fragment_image,container,false);  

  }

}

Fourth , Rewrite the activity_main.xml file,add fragment element.

  <fragment

    android:id = "@+id/main_fragmen"

    android:name = "com.bodor.ImageFrament"

    android:layout_width = "match_parent"

    android:layout_height = "height"

    tools:layout = "@layout/fragment_image"

  />

Fifth , Just test fragment with phone Emulator

Sixth , Creat Android resource diectory,make resource type equle layout,then selected smallest Screen width,

   Creat layout folder for another screen size sm720 = 10.1"tablet. folder Named layout-sw 720dp.

Seven , in progetct package ,find layout-sw 720dp folder.new layout resource named activity_main.xml too. Creat activity_main for tablet screent size.

Eight ,Multiple Screen size but with just one MainActivity to manage control .

   ImageView img = (ImageView)findViewById(R.id.imageVIew);

  img.setOnclickListener(new View.OnClickListener(){

    @Override

    public void onClick(View v){

    Toast.makeText(getApplicationContext,"",Toast.LENGTH).show();
    

}

  }

posted on 2017-09-21 21:10  L1nus  阅读(129)  评论(0)    收藏  举报

导航