Java 根据父对象的尺寸设置宽度和高度';谷歌的母公司安卓工作室

Java 根据父对象的尺寸设置宽度和高度';谷歌的母公司安卓工作室,java,android-studio,imageview,horizontalscrollview,Java,Android Studio,Imageview,Horizontalscrollview,我在一个线性布局中动态添加ImageView,它位于水平滚动视图中 现在,我想基于此水平滚动视图的父线性布局设置这些图像视图的宽度和高度 这是我的xml(信息\u imagescrollview\u item.xml): 如何将每个imageView设置为与xml中的parentlayout具有相同的宽度和高度?可以通过代码更改动态视图的尺寸。因此,我打赌在将图像视图添加到线性布局之前,您应该在for循环中更改图像视图的布局参数,如下所示: for(Object intObj : page.co

我在一个线性布局中动态添加ImageView,它位于水平滚动视图中

现在,我想基于此水平滚动视图的父线性布局设置这些图像视图的宽度和高度

这是我的xml(信息\u imagescrollview\u item.xml):


如何将每个imageView设置为与xml中的parentlayout具有相同的宽度和高度?

可以通过代码更改动态视图的尺寸。因此,我打赌在将
图像视图添加到线性布局之前,您应该在
for
循环中更改
图像视图的布局参数,如下所示:

for(Object intObj : page.content) {
    ImageView imageView = new ImageView(this.getContext());
    Drawable myDrawable = getResources().getDrawable((int) intObj);
    imageView.setImageDrawable(myDrawable);
    //Changing height...
    imageView.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
    //...and width
    imageView.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
    scrollViewLayout.addView(imageView);
}

这将把
ImageView
的宽度和高度设置为包含的(父项)
LinearLayout
的宽度和高度。

如果我添加ImageView.getLayoutParams().width=ViewGroup.LayoutParams.MATCH\u父项;图像仍然几乎是屏幕宽度的两倍。是否要像在gallery应用程序中那样逐个滚动图像?是的。但是在两个文本视图之间,我可以要求您发送一个草图链接,或者用它更新您的答案吗?我不想一直猜测你到底想创造什么。。。
View contentView = inflater.inflate(R.layout.information_imagescrollview_item, container, false);
LinearLayout scrollViewLayout = (LinearLayout) contentView.findViewById(R.id.linear);
for(Object intObj : page.content) {
    ImageView imageView = new ImageView(this.getContext());
    Drawable myDrawable = getResources().getDrawable((int) intObj);
    imageView.setImageDrawable(myDrawable);
    scrollViewLayout.addView(imageView);
}
page.addView(contentView);
for(Object intObj : page.content) {
    ImageView imageView = new ImageView(this.getContext());
    Drawable myDrawable = getResources().getDrawable((int) intObj);
    imageView.setImageDrawable(myDrawable);
    //Changing height...
    imageView.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
    //...and width
    imageView.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
    scrollViewLayout.addView(imageView);
}