小编Gus*_*Gus的帖子

每个字段多个GSON @SerializedName?

在Gson中有没有办法将多个JSON字段映射到单个Java对象成员变量?

假设我有一个Java类......

public class MyClass {
    String id;
    String name;
}
Run Code Online (Sandbox Code Playgroud)

我想使用这个有两种不同服务的单一类.但是,这两种服务在返回数据方面有所不同......

{ "id": 2341, "person": "Bob" }
Run Code Online (Sandbox Code Playgroud)

......而且......

{ "id": 5382, "user": "Mary" }
Run Code Online (Sandbox Code Playgroud)

... 分别.

有没有办法将JSON字符串中的"person""user"字段映射到nameJava对象中的字段?

(注意:我只需要从JSON字符串转换为Java对象 - 从不相反.)

java json gson

88
推荐指数
4
解决办法
3万
查看次数

Android VideoView比例缩放

在Android的VideoView中,有没有办法实现与ImageView.ScaleType.CENTER_CROP相同的效果?

也就是说,我希望我的VideoView能够播放视频,使其在不失真的情况下填满整个屏幕.如果视频宽高比不完全适合屏幕,则应裁剪而不是扭曲.

以下解决方案将填满屏幕,但不保持视频的宽高比:https: //stackoverflow.com/a/6927300/1068656

此解决方案保持视频的宽高比,但不会填满整个屏幕(视频会缩放,直到较长的一侧到达屏幕边缘,从而在侧面引入条形图):https: //stackoverflow.com/a/4855315/1068656

video android android-layout android-videoview

15
推荐指数
2
解决办法
6606
查看次数

如何使用RelativeLayout使视图居中?

我想知道如何使用RelativeLayout将View放在两个其他视图之间(或在视图和父边缘之间).

例如,如果我有以下...

在此输入图像描述

如何使用RelativeLayout将Button垂直居中在ImageView和屏幕底部?

我正在寻找一个解决方案......

  • Button没有以任何方式拉伸
  • 没有嵌套布局

我正在尝试在XML布局中执行此操作(不是以编程方式).

android android-layout android-relativelayout

14
推荐指数
1
解决办法
2万
查看次数

如何将Baseline与多行TextView的底线对齐?

我有两个TextViews并排.假设左侧TextView为1行,右侧TextView为2行.有没有办法将左侧TextView 的基线与右侧TextView中的最后一行对齐?

我愿意使用可以实现此目的的任何布局(RelativeLayout,LinearLayout等).

(android:layout_alignBaselineAndroid中的默认行为是它对齐顶行的基线.)

android android-layout

11
推荐指数
1
解决办法
1614
查看次数

如何将Android库资源设为私有?

如何将我的Android库模块中的资源(字符串,维度,颜色等)设为私有?

我已经尝试了两种记录的方法来做到这一点,但都没有工作......

  1. 官方Android doc创建一个 res/values/public.xml不起作用; 所有资源在使用此库的应用程序中保持公开.
  2. 按照Chris Banes的说明(并在StackOverflow的回答中重申)创建 res-public/values/public.xml文件夹也不起作用; 所有资源都是私有的,但public.xml 文件中列出的资源不是公开的.

有没有人有关于使图书馆资源私密的明确指示?是否有任何开源库已正确地将其资源私有化?

我正在使用...

  • Android Studio v2.2.3
  • buildToolsVersion "24.0.2"
  • com.android.tools.build:gradle:2.2.3

android android-library android-resources android-studio android-gradle-plugin

10
推荐指数
2
解决办法
3511
查看次数

批处理参数%~s1给出了不正确的8.3短名称

我正在尝试在Windows XP中编写一个批处理文件,它接受一个完全限定的路径名​​并输出8.3短名称版本...

@echo off
echo "%~s1"
Run Code Online (Sandbox Code Playgroud)

我遇到过一个特殊情况,它输出的路径和文件不正确......

C:\>test.bat "C:\Documents and Settings\angus\Local Settings\Temporary Internet Files\Content.IE5\2JSTM34V\62[1].ja2"
"C:\DOCUME~1\angus\LOCALS~1\TEMPOR~1\Content.IE5\2JSTM34V\62_1_~1.JA2M34V\62[1].ja2"
Run Code Online (Sandbox Code Playgroud)

请注意,上述输出("C:\ DOCUME~1\angus\LOCALS~1\TEMPOR~1\Content.IE5\2JSTM34V\62_1_~1.JA2M34V\62 [1] .ja2")不存在.但是,如果从该输出中删除".JA2M34V\62 [1]"部分,则生成的字符串将是原始输入文件的有效路径.

这似乎是在文件名中使用括号([])的问题.如果我在同一目录中创建文件62.ja2,输出将是正确的...

C:\>test.bat "C:\Documents and Settings\angus\Local Settings\Temporary Internet Files\Content.IE5\2JSTM34V\62.ja2"
"C:\DOCUME~1\angus\LOCALS~1\TEMPOR~1\Content.IE5\2JSTM34V\62.ja2"
Run Code Online (Sandbox Code Playgroud)

这是Windows中的错误吗?有没有人知道是否有一个解决方法允许批处理文件正确处理此文件名?

windows parameters filenames batch-file short

7
推荐指数
1
解决办法
2539
查看次数

ConstraintLayout中的保证金行为

android:layout_margin*在ConstraintLayout中使用时,我很难理解margin()的行为。边距似乎仅在某些情况下有效,我希望有人可以向我解释(或确认这是ConstraintLayout错误)。

我有以下布局...

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
         android:id="@+id/leftView"
         android:layout_width="0dp"
         android:layout_height="100dp"
         android:layout_marginEnd="20dp"
         android:background="@android:color/holo_blue_dark"
         app:layout_constraintEnd_toStartOf="@+id/rightView"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent"/>

     <View
         android:id="@+id/rightView"
         android:layout_width="100dp"
         android:layout_height="100dp"
         android:background="@android:color/holo_green_light"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

...产生以下输出...

预期产量

但是,当我将边距从更改leftViewrightView...

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/leftView"
        android:layout_width="0dp"
        android:layout_height="100dp"
        android:background="@android:color/holo_blue_dark"
        app:layout_constraintEnd_toStartOf="@+id/rightView"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <View
        android:id="@+id/rightView"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginStart="20dp"
        android:background="@android:color/holo_green_light"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout> 
Run Code Online (Sandbox Code Playgroud)

...页边距意外消失...

意外的输出

有人可以解释这是否是预期的行为吗?如果是,为什么?

android android-layout android-constraintlayout

7
推荐指数
1
解决办法
2333
查看次数

将视图底部与文本基线对齐

在ConstraintLayout中,是否可以将View(例如ImageView)的底部与TextView的基线对齐?我期望会有类似的约束app:layout_constraintBottom_toBaselineOf,但没有类似的约束存在。

注意:我已经尝试过了app:layout_constraintBaseline_toBaselineOf,但是看起来只有在TextView上定义时才起作用。

android android-layout android-constraintlayout

6
推荐指数
2
解决办法
1906
查看次数

如何设置以对话框为主题的活动的百分比宽度

我有一个带有对话框主题的Activity(Theme.Holo.DialogWhenLarge).它看起来太窄了,我希望它能填满更大比例的屏幕.我试图通过覆盖windowMinWidthMinorwindowMinWidthMajor属性来实现此目的.

我的Activity使用的主题看起来像这样......

<style name="MyTheme" parent="@android:style/Theme.Holo.DialogWhenLarge">
    <item name="android:windowMinWidthMajor">90%</item>
    <item name="android:windowMinWidthMinor">90%</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但是,它似乎windowMinWidthMajorwindowMinWidthMinor没有效果.谁能解释我做错了什么?

android android-layout

5
推荐指数
1
解决办法
3275
查看次数