繁体   English   中英

从Java文件动态设置视图

[英]setting the view dynamically from the java file

我试图通过使用特定数量的linearlayouts并设置源图像来使Java文件以动态方式设置活动视图
所以如何使用Java代码创建特定数量的图像视图

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

<ScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent">


    <ImageView
    android:id="@+id/menuline"
    android:layout_width="match_parent"
    android:layout_height="85dp" >

</ImageView>
</LinearLayout>    



</ScrollView>

要创建ImageView的(假设thisActivity ):

ImageView imageView = new ImageView(this);
imageView.set(...) //configure your imageView according your needs
...
imageView.setLayoutParam(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,85); //set width and height

要将您的imageView添加到linearLayout中:

linearLayout.addView(imageView);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM