androidstudio滚动布局,AndroidStudio中滚动视图ScrollView的使用_百...

androidstudio滚动布局,AndroidStudio中滚动视图ScrollView的使用_百...

2023年7月13日发(作者:)

androidstudio滚动布局,AndroidStudio中滚动视图ScrollView的使⽤滚动视图有两种,⼀种是ScrollView,另⼀种是HorizontalScrollView.下⾯是activity_布局⽂件管理器xmlns:app="/apk/res-auto"xmlns:tools="/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity">android:layout_width="wrap_content"android:layout_height="wrap_content">android:textSize="50sp"android:text="@string/content"android:layout_width="wrap_content"android:layout_height="wrap_content" />请注意:ScrollView⾥只能有⼀个⼦控件,如果有多个就会报错!!如果将我们将上⾯代码中的TextView再复制⼀份,如下:xmlns:app="/apk/res-auto"xmlns:tools="/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity">android:layout_width="wrap_content"android:layout_height="wrap_content">android:textSize="50sp"android:text="@string/content"android:layout_width="wrap_content"android:layout_height="wrap_content" />android:textSize="50sp"android:text="@string/content"android:layout_width="wrap_content"android:layout_height="wrap_content" /> //两个会报错!上⾯的代码是错的因为有两个⼦控件,AS将显⽰如下错误,说明ScrollView只能有⼀个直接的⼦控件如果想要⽤两个TextView的话可以⽤线性布局管理器LinearLayout(或者其它的)将括起来,这样就不会报错了。还有⼀种⽅法创建滚动视图:⾸先看下图下⾯的代码坐下往上看吧,贴反了(吐⼝⽔(¯﹃¯)):⽂件package e.c_ication;import patActivity;import ;import iew;import Layout;import View;import ew;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {te(savedInstanceState);setContentView(ty_main);LinearLayout ll = ewById();LinearLayout ll2 = new LinearLayout();entation(AL);ScrollView scrollView = new ScrollView();w(scrollView);w(ll2);ImageView imageView = new ImageView();geResource(03);w(imageView);TextView textView = new TextView();t(nary);w(textView);}}//这段代码好⽐⼀个线性布局管理器⾥嵌套⼀个线性布局管理器,⼦线性布局管理器⾥⼜有2个控件,⼀个是ImageView, 另⼀个是⽂件My Application123n我爱你n123n我爱你n123n我爱你n123n我爱你n123n我爱你n123n我爱你n123n我爱你n123n我爱你n123n我爱你n123n我爱你n123n我爱你n123n我爱你n123n我爱你n123n我爱你n123n我爱你n123n我爱你nactivity_⽂件xmlns:app="/apk/res-auto"xmlns:tools="/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"android:id="@+id/ll"android:orientation="vertical"android:padding="16dp">

发布者:admin,转转请注明出处:http://www.yc00.com/web/1689217235a222432.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信