Hi guys I am trying to build a layout but I am not able to understand how to build it what I am trying to do is to add a Image whose height and width will be of screen size and below it will be a description about the Image which the users can view when they scroll it but the whole screen will be consisting of image only until the user scrolls the text below will not be displayed
#create x,y coordinates
x = numpy.random.choice(10,10)
y = numpy.random.choice(10,10)
#create an array of colors based on direction of line (0=r, 1=g, 2=b)
colors = []
#create an array that is one position away from original
#to determine direction of line
yCopy = list(y[1:])
for y1,y2 in zip(y,yCopy):
if y1 > y2:
colors.append(0)
elif y1 < y2:
colors.append(1)
else:
colors.append(2)
#add tenth spot to array as loop only does nine
colors.append(2)
#create a numpy array of colors
categories = numpy.array(colors)
#create a color map with the three colors
colormap = numpy.array([matplotlib.colors.colorConverter.to_rgb('r'),matplotlib.colors.colorConverter.to_rgb('g'),matplotlib.colors.colorConverter.to_rgb('b')])
#plot line
matplotlib.axes.plot(x,y,color=colormap[categories])
you can see in the below link the way i want the layout to be
http://postimg.org/image/avgmk6pi3/
please feel free to drop in comments if you need any additional details
EDIT 1
After trying rachel solution I am getting this
http://postimg.org/image/tdb02gu9l/
now as you can see in the image the image view is taking whole width of the screen which is fine but it doesn't take the whole height of the screen if i write match_parent to the imageview layout_height the image takes the whole screen but it doesn't allow me to scroll
答案 0 :(得分:0)
听起来您需要做一些工作来获取设备的屏幕尺寸,然后使用它以编程方式设置图像视图的大小。
有关计算设备屏幕尺寸的详细信息,请参阅此处接受的答案:Android Layout, view height is equal to screen size
答案 1 :(得分:0)
经过对谷歌和stackoverflow的一些研究终于得到了一个方法后,最终得到了它的工作
所以这里首先是你的活动/片段
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.second_frag, container, false);
img = (ImageView) v.findViewById(R.id.imageView);
Drawable drawable = getResources().getDrawable(R.drawable.dp);
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
float scalingFactor = this.getBitmapScalingFactor(bitmap);
Bitmap newBitmap = Util.ScaleBitmap(bitmap, scalingFactor);
// Set the bitmap as the ImageView source
this.img.setImageBitmap(newBitmap);
return v;
}
private float getBitmapScalingFactor(Bitmap bm) {
// Get display width from device
int displayWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth();
// Get margin to use it for calculating to max width of the ImageView
RelativeLayout.LayoutParams layoutParams =
(RelativeLayout.LayoutParams)this.img.getLayoutParams();
int leftMargin = layoutParams.leftMargin;
int rightMargin = layoutParams.rightMargin;
// Calculate the max width of the imageView
int imageViewWidth = displayWidth - (leftMargin + rightMargin);
// Calculate scaling factor and return it
return ( (float) imageViewWidth / (float) bm.getWidth() );
}
因为我正在使用片段我有onCreateView onCreate将用于使用活动的人
并创建一个Utils类
public class Util {
public static Bitmap ScaleBitmap(Bitmap bm, float scalingFactor) {
int scaleHeight = (int) (bm.getHeight() * scalingFactor);
int scaleWidth = (int) (bm.getWidth() * scalingFactor);
return Bitmap.createScaledBitmap(bm, scaleWidth, scaleHeight, true);
}
如果你们有更好的解决方案,请告诉我们