我试图获得一个视图的高度,它一直返回0.
这是我尝试过的:
View hourView = View.inflate(mContext, R.layout.calendar_hour_item,null);
hourViewHeight = hourView.findViewById(R.id.mainLayout).getHeight();
Run Code Online (Sandbox Code Playgroud)
我也试过hourViewHeight = hourView.getHeight();但没有快乐.
我在这里的initialize()方法中调用这两行:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calendar_day_screen);
Intent intent = getIntent();
mDate = new DateTime(intent.getStringExtra("date"));
circleIcon = (ImageView) findViewById(R.id.circle);
mHoursLayout = (RelativeLayout) findViewById(R.id.dayLayout);
TopBarUtil topBar = new TopBarUtil(getApplicationContext());
circleIcon.setOnClickListener(topBar.onActionClickListener());
mContext = getApplicationContext();
initialize();
}
Run Code Online (Sandbox Code Playgroud)
这是我的xml布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/mainLayout" android:background="@layout/border">
<TextView android:text="12am" android:id="@+id/hourTextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我basicllay想要获得上面的xml布局的高度,但它总是返回0.
编辑:我也尝试过这样做:
@Override
protected void onStart() {
// TODO Auto-generated method stub …Run Code Online (Sandbox Code Playgroud) 我试图以一种方式旋转/翻转imageView,其中所讨论的图像(卡片)翻转到它的另一侧,即沿其Z轴旋转3d动画.那可能吗?
我在下面写了这个代码,但它只在2d中旋转,只改变它的方向而不是它的一面.
// animations
private static final float ROTATE_FROM = 0.0f;
private static final float ROTATE_TO = -10.0f * 360.0f;
private RotateAnimation mRotateAnimation;
mRotateAnimation = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
mRotateAnimation.setDuration((long)2 * 150);
mRotateAnimation.setRepeatCount(0);
mCardImage.startAnimation(mRotateAnimation);
Run Code Online (Sandbox Code Playgroud) 我正在使用java开发SDK,我的问题是隐藏某些java类/包,因此没有第三方应用程序使用这个sdk暴露给这些下划线类
我知道如果sdk中的所有类对象都在一个包内,我可以将默认/受保护的访问修饰符分配给我想要隐藏的类.但是,像许多java项目一样,像我的sdk这样的java项目由不同的包组成,它们适当地对relivant java类进行分组.
这意味着如果我想隐藏/保护com.abc中的类,那么位于com.a中的世界可见的主根类将无法访问com.abc中受保护的类等
我如何为此提供解决方案,而不是仅仅将所有类转储到一个大型包中?
谢谢.
您好我正在尝试使用gradle构建并重命名我的aar文件,但得到上述错误:
A problem occurred evaluating project ':app'.
> Could not find property 'outputs' on BuildType_Decorated{name=variant, debuggable=false, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscriptDebuggable=false, renderscriptOptimLevel=3, applicationIdSuffix=null, versionNameSuffix=null, minifyEnabled=false, zipAlignEnabled=true, signingConfig=null, embedMicroApp=true, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}}.
Run Code Online (Sandbox Code Playgroud)
这是我在gradle上的完整构建脚本
apply plugin: 'com.android.library'
android.libraryVariants.all { variant ->
def alignedOutputFile = output.outputFile
def unalignedOutputFile = output.packageApplication.outputFile
logger.warn('You got to variant: ' + variant + ' and output: ' + output)
// Customise APK filenames (to include build version)
if (variant.buildType.zipAlignEnabled) {
// normal APK
output.outputFile = new File(alignedOutputFile.parent, …Run Code Online (Sandbox Code Playgroud) 每当我运行单元测试时,我在尝试从自定义config.xml文件中检索字符串值时会收到此错误.
背景:
该项目本身是一个库apk项目,使用和引用另一个库APK项目.
当项目本身尝试启动一个新对象时,会发生错误,该对象是引用的库apk项目中包含的超类的子类.
该问题在下面解释了更多
因错误而失败的特定代码行是下面定义的静态变量:
protected static final String ANDROID_CONFIG_ID = LibraryApplication.getApplication().getString(R.string.api_checkout_config_id_override);
Run Code Online (Sandbox Code Playgroud)
它失败并出现以下错误:
java.lang.NoClassDefFoundError: com/jon/commonlib/R$string
Run Code Online (Sandbox Code Playgroud)
如果您想知道,commonLib是引用的库apk.
这是我的单元测试
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, manifest=Config.NONE)
public class TestSearchShows {
@Test
public void testSearchJsonFile(){
EventsTestHelper testHelper = new EventsTestHelper(RuntimeEnvironment.application);
try {
ShowsList showList = testHelper.getShowList(new SearchEvent());
if(showList.getShows().size() < 0){
Assert.fail("show list is empty");
}
} catch (IOException e) {
e.printStackTrace();
Assert.fail(e.toString());
}
}
}
Run Code Online (Sandbox Code Playgroud)
EventsTestHelper是名为NetworkHelper的超类的子类,如下所示:
public abstract class NetworkHelper<T, P, S> implements NetworkConstants {
protected static final String ANDROID_CONFIG_ID = LibraryApplication.getApplication().getString(R.string.api_checkout_config_id_override);
//other stuff …Run Code Online (Sandbox Code Playgroud) 嗨我正在使用robolectric版本3.0进行单元测试我的应用程序,并在src/test/assets下有一些文件包含的asssets文件夹,但不断获取fileNotFound.
这是我的测试代码:
```
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, manifest = Config.NONE)
public class ShowsDatesTest {
@Test
public void testResponse(){
BufferedReader = getBufferedResponseFromFile("response.json");
}
private BufferedReader getBufferedResponseFromFile(String json) throws IOException {
mContext = RuntimeEnvironment.application;
InputStream jsonResponse = mContext.getAssets().open(json);
BufferedReader br = new BufferedReader(new InputStreamReader(jsonResponse, "UTF-8"));
return br;
}
}
Run Code Online (Sandbox Code Playgroud)
```
这是我的gradle文件中的sourceset和依赖项:```
production {
res.srcDir 'build-config/production/res'
test.java.srcDirs += 'src/main/java'
test.java.srcDirs += "build/generated/source/r/production"
test.java.srcDirs += "build/generated/source/buildConfig/production"
test.assets.srcDir file('src/test/assets')
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.1.+'
compile 'com.google.code.gson:gson:2.3'
testCompile('org.robolectric:robolectric:3.0') {
exclude group: …Run Code Online (Sandbox Code Playgroud) android unit-testing gradle robolectric robolectric-gradle-plugin
有谁知道android是否支持在一个项目中编译的多个Android模块之间共享相同的共享首选项?
我有两个共享首选项,目前当我尝试从当前模块之外的共享prefence访问某些数据时,它不起作用并创建一个新的sharedPrefence而不是
例
第一单元:
mSharedPreferences = context.getSharedPreferences(
"pref", Context.MODE_PRIVATE);
Run Code Online (Sandbox Code Playgroud)
第二单元:
mSharedPreferences = context.getSharedPreferences(
"pref", Context.MODE_PRIVATE);
Run Code Online (Sandbox Code Playgroud)
它创建了两个首选项文件,而不是两个模块可以共享数据的文件
@Entity
data class Products(
val id:String,
val title: String,
val description: String,
val imgUrl: String,
val usageRules : List<String>, //what happens here?
)
Run Code Online (Sandbox Code Playgroud)
我正在玩 ROOM for android,我看到的大多数示例都没有解释如何创建一个包含 arrayList 的实体表。
有 @Embedded 似乎只嵌套另一个对象,但我试图嵌套一个名为 usageRules 的对象列表
我需要创建一个单独的使用规则表吗?问题是,每个使用规则都可以包含在上面的多个产品中,并且一个产品可以定义多个使用规则,因此它是多对多的关系。
ROOM 可以实现吗?
我知道在 Realm 中,我可以简单地将 UsageRule List<> 转换为 RealmList<>。ROOM 有等价物吗?
另一种选择是因为它只是一个字符串列表。我可以简单地创建一个名为 allUsage 的新表实体字段,该字段使用分隔符存储特定产品上的所有使用规则,然后当我想再次从 ROOM 构造数据对象时,我可以通过执行 allUsage.Split(.. )
仍然宁愿用另一种方式来做,因为我可能会遇到一个场景,其中使用规则不仅仅是一个字符串列表,而是一个对象列表......
android android-room android-architecture-components android-jetpack
您可以在我的AppComponent中添加测试模块吗?
下面是我的appComponent的真实表现
@Singleton
@Component(modules = arrayOf(MainModule::class,
AnalyticsModule::class,
MainAndroidBinding::class,
AccountAndroidBinding::class,
AndroidSupportInjectionModule::class,
HomeAndroidBinding::class,
NetworkModule::class))
interface ApplicationComponent : AndroidInjector<DaggerApplication> {
fun inject(myApplication: MyApplication)
override fun inject(instance: DaggerApplication)
@Component.Builder
interface Builder {
@BindsInstance
fun application(applicaton: Application): Builder
fun build(): ApplicationComponent
}
}
Run Code Online (Sandbox Code Playgroud)
我可以直接将测试模块添加到testAppComponent,但它不能为我提供动态添加不同testModule的灵活性.
@Singleton
@Component(modules = [
(MainModuleTest::class),
(TestMainAndroidBindingTest::class),
(AccountAndroidBindingTest::class),
(AnalyticsModuleTest::class),
(AndroidSupportInjectionModule::class),
(NetworkModuleTest::class)])
interface TestAppComponent : ApplicationComponent {
fun inject(launchActivityTest: LaunchActivityTest)
@Component.Builder
interface Builder {
@BindsInstance
fun application(applicaton: Application): Builder
fun build(): TestAppComponent
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的MyApplication类
class MyApplication : DaggerApplication() {
companion object { …Run Code Online (Sandbox Code Playgroud) android automated-tests unit-testing android-espresso dagger-2
嗨,我正在尝试使用 kotlin koin 将变量加载/注入到我的单元测试中,但失败了,当我尝试使用这些变量时,我收到了 no class def found 错误。
下面是我的模块:
val testModules = module {
single<NetworkControllerContract> {
Mockito.mock(NetworkControllerContract::class.java)
}
single {
Room.inMemoryDatabaseBuilder(ApplicationProvider.getApplicationContext<Context>(),
PostDatabase::class.java).allowMainThreadQueries().build()
}
single<PostRepositoryContract> { PostRepository(get(), get()) }
// factory { GetAllDataUseCase(get()) }
single { create<GetAllDataUseCase>() }
single { GetCommentCountUseCase(get()) }
single { GetPostDetailsUseCase(get()) }
single { GetPostListUseCase(get()) }
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试课
class UseCaseUnitTests : KoinTest {
@get:Rule
var rule: TestRule = InstantTaskExecutorRule()
val getAllDataUseCase: GetAllDataUseCase by inject()
val getCommentCountUseCase: GetCommentCountUseCase by inject()
val getPostDetailsUseCase: GetPostDetailsUseCase by inject()
val …Run Code Online (Sandbox Code Playgroud) android ×9
unit-testing ×3
robolectric ×2
android-architecture-components ×1
android-room ×1
dagger-2 ×1
gradle ×1
java ×1
junit ×1
junit4 ×1
koin ×1
kotlin ×1