当前位置:   article > 正文

Fragment简易新闻_android中通过fragement实现 新闻阅读的代码案例

android中通过fragement实现 新闻阅读的代码案例

这里写图片描述

下面是xml布局文件
activity_main.xml: 屏幕宽度小于600dp加载这个布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <fragment
      android:id="@+id/news_title"
      android:name="com.ukulele.fragmentbestpractice.NewsTitleFragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:layout_editor_absoluteY="8dp"
      tools:layout_editor_absoluteX="8dp" />

</LinearLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

activity_main.xml(sw600dp): 屏幕宽度大于600dp加载这个布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">

   <fragment
       android:id="@+id/news_title_fragment"
       android:name="com.ukulele.fragmentbestpractice.NewsTitleFragment"
       android:layout_width="0dp"
       android:layout_height="match_parent"
       android:layout_weight="1"/>

    <fragment
        android:id="@+id/news_content_fragment"
        android:name="com.ukulele.fragmentbestpractice.NewsContentFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3"/>

</LinearLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

news_title_frag.xml:新闻标题碎片需要加载的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/355330
推荐阅读
相关标签
  

闽ICP备14008679号