我正在构建一个UI,它在XML中都是静态定义的.所有这些都在整个地方都有重量,虽然它看起来正确,但我希望看到事情确实具有正确的高度和所有.问题是无论我在哪里调用.getHeight()我的格式布局都得到了0.我在onCreate()和onStart()中都尝试过.一样.也适用于所有UI对象.任何的想法?
package com.app.conekta;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.Toast;
public class Conekta extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onResume() {
super.onResume();
FrameLayout fl1 = (FrameLayout) findViewById(R.id.headerFrameLayout);
FrameLayout fl2 = (FrameLayout) findViewById(R.id.footerFrameLayout);
Button b=(Button) findViewById(R.id.searchButton);
Log.d("CONEKTA", String.valueOf(b.getHeight()));
}
}
Run Code Online (Sandbox Code Playgroud)
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" …Run Code Online (Sandbox Code Playgroud) 我正在尝试解决一个旧的kotlin项目中的问题.但问题是我无法编译代码.我尝试在Android Studio和IntelliJ中编译和运行.我有同样的错误.
以下是错误:
Error:(174, 25) Expression 'length' of type 'Int' cannot be invoked as a function. The function 'invoke()' is not found
Error:(176, 60) Unresolved reference: charAt
Error:(148, 67) Expression 'size' of type 'Int' cannot be invoked as a function. The function 'invoke()' is not found
Error:(107, 76) Expression 'ordinal' of type 'Int' cannot be invoked as a function. The function 'invoke()' is not found
Run Code Online (Sandbox Code Playgroud)
我的gradle脚本:
buildscript {
ext.kotlin_version = '1.0.4'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath …Run Code Online (Sandbox Code Playgroud) 我不确定这是否可行,或者如果我接近这个挑战是错误的.我正在制作2D平台游戏,所以当你到达屏幕边缘(宽度)时,会出现一个新的地图部分.目前,我为地图的每个部分制作了单个图像.问题是,在较大的设备上,这会留下大量的空白屏幕,而Image只适合特定的设备.
现在我想知道,我可以将我的ImageView(MAP)设置为负X值,然后当角色碰到边缘时,地图会向右移动(X会更高).
我正在使用XML(Java也很好),我没有CLUE如何处理这个问题.
我Fresco在我的应用程序中使用库来加载图像。问题是我无法将图像高度设置为"wrap_content"因为 库中"wrap_content"不支持Fresco。那么如何使用DraweeView?使我的图像看起来不错?我在这里查看,但找不到解决此问题的方法:frescolib/wrap_content
例如:
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/intro_image1"
android:layout_width="match_parent"
android:layout_height= // Can't use "wrap_content"
fresco:placeholderImage="@drawable/placeholder_image" />
Run Code Online (Sandbox Code Playgroud)
顺便说一句,图像尺寸为 730*760
每当我尝试设置 LinearLayout 的高度时,我总是会遇到以下异常:
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
LinearLayout.LayoutParams hide = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
LinearLayout.LayoutParams show = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100);
driverMainOptions.setLayoutParams(hide);
mapDirections.setLayoutParams(show);
Run Code Online (Sandbox Code Playgroud)
是否需要特定的导入语句才能正确执行?