我目前正在尝试使用Android制作基于旧学校战舰棋盘游戏的游戏.我现在只是在试图感受它以及我可能需要制作游戏的组件.
基本上我目前在布局xml文件中的内容如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<org.greene.battleship.BoardView
android:id="@+id/board_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.greene.battleship.ShipView
android:id="@+id/ships_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我希望BoardView只占用屏幕的某个部分,即视图应该是我想在此视图中创建的内容的大小.在这种情况下,它是2D板.这是通过从扩展View覆盖onMeasure()方法来完成的.视图的宽度保持不变,但高度与宽度相同,给出了完美的正方形.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
int parent_width = MeasureSpec.getSize(widthMeasureSpec);
this.setMeasuredDimension(parent_width, parent_width);
Log.d("BOARD_VIEW", "BoardView.onMeasure : width = " + this.getMeasuredWidth() + ", height = "
+ this.getMeasuredHeight());
}
Run Code Online (Sandbox Code Playgroud)
我通过覆盖onSizeChanged()函数的视图并检查那里的值来检查视图维度是否已更改.
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh){
Log.d("BOARD_VIEW", "BoardView.onSizeChanged : width = " + w + ", height …Run Code Online (Sandbox Code Playgroud) 在CSS中使用rem作为单位时,缩放在Safari(PC和Mac)中都不起作用.
示例位于http://jsfiddle.net/L25Pz/3/
标记:
<div>
<img src="http://www.google.com/images/srpr/logo3w.png" />
<p>Lorem ipsum dolor sit amet</p>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
html { font-size:62.5% }
div { background:url(http://www.google.com/images/srpr/logo3w.png); background-size:275px 95px; background-size:27.5rem 9.5rem; background-repeat:no-repeat; }
img { width:27.5rem; height:9.5rem; }
p { font-size:5rem; }
@media only screen and (max-width: 500px) {
html { font-size:50%;} /* should render everything * 0.8 */
}
Run Code Online (Sandbox Code Playgroud)
...当浏览器窗口宽度超过600px时,在所有浏览器中呈现大小为275px*95px的图像.此外,在触发媒体查询时,图像和背景将其宽度和高度调整为220px*76px.
但是 - 使用Safari,宽度和高度设置为247px*75px.哪个不是*0.8,这是别的......
另一方面,段落的字体大小正确呈现:挂钩在查询上时为40px.
如果你问我,我会觉得很奇怪.有人有解决方案吗?
有没有办法用java知道swf文件的原始宽度和高度?
int width, height;
// my stream contains an image or a swf file
InputStream stream = file.getInputStream();
// mediaType has been set with the help of file extension
switch (mediaType)
{
case IMAGE:
BufferedImage img = ImageIO.read(stream);
width = img.getWidth();
height = img.getHeight();
break;
case FLASH:
// what is the code here ?
break;
}
Run Code Online (Sandbox Code Playgroud) 我在UIViewController中有一个UIScrollView(由ImageViewController子类).ViewController本身是NavigationController堆栈的一部分.现在,除了有一个导航栏,我希望ScrollView能够占用屏幕上所有可用的空间.然后,scrollview中的UIImageView应该填充滚动视图的可用空间.您可以在此帖子的底部看到当前状态.
class ImageViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var scrollView: UIScrollView!
var imageView: UIImageView?
var image: UIImage?
override func viewDidLoad() {
super.viewDidLoad()
scrollView.delegate = self
if let image = image {
imageView = UIImageView(image: image)
if let imageView = imageView {
imageView.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: image.size)
scrollView.addSubview(imageView)
scrollView.contentSize = image.size
let scaleHeight = scrollView.frame.size.height / scrollView.contentSize.height
let scaleWidth = scrollView.frame.size.width / scrollView.contentSize.width
let minimumScale:CGFloat = min(scaleHeight, scaleWidth)
let maximumScale:CGFloat = max(scaleHeight, scaleWidth)
scrollView.minimumZoomScale = minimumScale
scrollView.maximumZoomScale …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种算法来找到最佳尺寸组合以实现所需的结果.
以下面的例子为例:
| A | B | C | y |
|--------|--------|-------|-----|
| dog | house1 | green | 30 |
| dog | house1 | blue | 15 |
| cat | house1 | green | 20 |
| cat | house2 | red | 5 |
| turtle | house3 | green | 50 |
Run Code Online (Sandbox Code Playgroud)
A,B,C是测量的尺寸.y是测量结果.
如果我想得到y> = 50的所有维度组合,那么结果将是:
turtle, house3, green
turtle, any, green
turtle, house3, any
turtle, any, any
any, house3, green
any, house3, any
any, …Run Code Online (Sandbox Code Playgroud) 我使用python包装器来调用c ++ dll库的函数.一个ctype由dll库返回,我将其转换为numpy数组
score = np.ctypeslib.as_array(score,1)
Run Code Online (Sandbox Code Playgroud)
但阵列没有形状?
score
>>> array(-0.019486344729027664)
score.shape
>>> ()
score[0]
>>> IndexError: too many indices for array
Run Code Online (Sandbox Code Playgroud)
如何从乐谱数组中提取双精度?
谢谢.
即使在回答和评论中应用建议后,看起来尺寸不匹配问题仍然存在。这也是要复制的确切代码和数据文件:https : //drive.google.com/drive/folders/1q67s0VhB-O7J8OtIhU2jmj7Kc4LxL3sf?usp=sharing
这个怎么改啊!?最新代码、模型摘要、使用的函数和我得到的错误如下
type_ae=='dcor'
#Wrappers for keras
def custom_loss1(y_true,y_pred):
dcor = -1*distance_correlation(y_true,encoded_layer)
return dcor
def custom_loss2(y_true,y_pred):
recon_loss = losses.categorical_crossentropy(y_true, y_pred)
return recon_loss
input_layer = Input(shape=(64,64,1))
encoded_layer = Conv2D(filters = 128, kernel_size = (5,5),padding = 'same',activation ='relu',
input_shape = (64,64,1))(input_layer)
encoded_layer = MaxPool2D(pool_size=(2,2))(encoded_layer)
encoded_layer = Dropout(0.25)(encoded_layer)
encoded_layer = (Conv2D(filters = 64, kernel_size = (3,3),padding = 'same',activation ='relu'))(encoded_layer)
encoded_layer = (MaxPool2D(pool_size=(2,2)))(encoded_layer)
encoded_layer = (Dropout(0.25))(encoded_layer)
encoded_layer = (Conv2D(filters = 64, kernel_size = (3,3),padding = 'same',activation ='relu'))(encoded_layer)
encoded_layer = (MaxPool2D(pool_size=(2,2)))(encoded_layer)
encoded_layer = …Run Code Online (Sandbox Code Playgroud) 我正在创建一个 xarray 数据集,如下所示:
import numpy as np
import xarray as xr
x_example = np.random.rand(1488,)
y_example = np.random.rand(1331,)
time_example = np.random.rand(120,)
rainfall_example = np.random.rand(120, 1331, 1488)
rainfall_dataset = xr.Dataset(
data_vars=dict(
rainfall_depth=(['time', 'y', 'x'], rainfall_example),
),
coords=dict(
time=(['time'], time_example),
x=(['x'], x_example),
y=(['y'], y_example)
)
)
Run Code Online (Sandbox Code Playgroud)
结果是这样的
而我跑步时的尺寸rainfall_example.dims是这样的Frozen({'time': 120, 'y': 1331, 'x': 1488})(这也可以从上面的结果中看出)。我知道xarray.Dataset.dims不能根据这里修改
我的问题是:我们如何才能将这些维度的顺序更改为这样的维度Frozen({'time': 120, 'x': 1488, 'y': 1331})而不更改其他任何内容(一切都将相同,只是维度的顺序发生了变化)?
Heyho伙伴,
目前我正在使用新的ConstraintLayout学习Android Studio 的新布局编辑器.
顺便说一句,我讨厌它.
但是我遇到了问题,如果我想用@dimen指定layout_height,它会被替换为dp值.
有人得到了这个问题吗?
Android Studio版本2.2.2和2.2.3相同的问题.
最新的gradle版本.
先谢谢你们!
编辑:
代码示例:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="@dimen/imageViewHeight"
app:srcCompat="@drawable/accept"
android:id="@+id/imageView"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
也在scrollview外面发生.
dimensions ×10
android ×3
java ×2
python ×2
algorithm ×1
arrays ×1
border ×1
css3 ×1
ctypes ×1
custom-view ×1
dataset ×1
dimension ×1
flash ×1
font-size ×1
keras ×1
numpy ×1
parent-child ×1
safari ×1
size ×1
uiimageview ×1
uiscrollview ×1
valueerror ×1