📜  Android中的NestedScrollView示例

📅  最后修改于: 2021-05-09 16:45:00             🧑  作者: Mango

NestedScrollView就像ScrollView一样,但是在新旧版本的Android上,它都同时充当嵌套滚动父级和子级。默认情况下启用。当需要在另一个滚动视图内滚动视图时,可以使用NestedScrollView 。例如,您已经在许多应用程序中看到了这一点 当我们打开pdf文件并且到达PDF末尾时,在pdf文件下方会显示一个广告。这就是NestedScrollView的用处通常,由于系统无法确定要滚动的视图,因此很难做到。让我们通过示例来讨论Android中NestedScrollView。

例子

步骤1:建立新专案

要在Android Studio中创建新项目,请参阅如何在Android Studio中创建/启动新项目。请注意,尽管我们将使用Java语言来实现该项目,但请选择Java作为语言。

第2步:在进入编码部分之前,请先执行一些预任务

  • 转到应用-> res->值->字符串.xml 并在字符串.xml文件中添加两个随机文本字符串,以在activity_main.xml文件中显示这些字符串。
XML

    GFG | NestedScrollView 
    
        Hadoop is a data processing tool used to process large size data over distributed
        commodity hardware. The trend of Big Data Hadoop market is on the boom and it’s
          not showing any kind of deceleration in its growth. Today, industries are capable
          of storing all the data generated at their business at an affordable price just
          because of Hadoop. Hadoop helps the industry to know their customer’s behavior,
          customers buying priorities i.e. what they loved the most, and click patterns,
          etc. Hadoop provides personalized recommendations and personalizes ad targeting
          features. Companies are generating thousands of petabytes of data every day so the
          demand for Big Data professionals is very high. Even after a few years,
          Hadoop will be considered as the must-learn skill for the data-scientist
          and Big Data Technology. Companies are investing big in it and it will become
          an in-demand skill in the future. Hadoop provides personalized recommendations
        and personalizes ad targeting
          features. Companies are generating thousands of petabytes of data every day so the
          demand for Big Data professionals is very high. Even after a few years,
          Hadoop will be considered as the must-learn skill for the data-scientist
          and Big Data Technology. Companies are investing big in it and it will become
          an in-demand skill in the future.
    
    
          Humans are coming closer to the internet at a very fast rate. It means that the
          volume of data Industries is gathering will increase as time passes because of
          more users. Industry’s are gradually analyzing the need for this useful information
          they are getting from their users. It is for sure that the data always tends to
          an increasing pattern so the company’s are eventually acquiring professionals
          skilled with Big Data Technologies. According to NASSCOM, India’s Big Data
          Market will reach 16 billion USD by 2025 from 2 billion USD. The growth of smart
          devices in India is growing at a very huge rate that will cause growth in the
          Big Data Market. Since Big Data is growing the demand for Big Data professionals
          will be high.  Hadoop provides personalized recommendations and personalizes ad targeting
          features. Companies are generating thousands of petabytes of data every day so the
          demand for Big Data professionals is very high. Even after a few years,
          Hadoop will be considered as the must-learn skill for the data-scientist
          and Big Data Technology. Companies are investing big in it and it will become
          an in-demand skill in the future.
    
  


XML


  
    
    
  
        
        
  
            
            
  
            
            


Java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
  
public class MainActivity extends AppCompatActivity {
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}


步骤3:设计UI

activity_main.xml文件中,添加NestedScrollView,然后在NestedScrollView内添加LinearLayout 并且里面的LinearLayout添加两个TextView中显示这些字符串.xml文件和一个按钮中创建的字符串 之间的TextView 这是activity_main.xml文件的代码。一个可以在NestedScrollView的LinearLayout中添加尽可能多的视图

XML格式



  
    
    
  
        
        
  
            
            
  
            
            

步骤4:使用MainActivity。 Java文件

MainActivity无关。 Java文件,因此请保持原样。

Java

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
  
public class MainActivity extends AppCompatActivity {
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

输出:在模拟器上运行

资源:

  • 从Github下载完整项目
  • 下载Apk文件
想要一个节奏更快,更具竞争性的环境来学习Android的基础知识吗?
单击此处,前往由我们的专家精心策划的指南,以使您立即做好行业准备!