我正在尝试找到解决以下问题的方法.我工作的应用程序要求用户通过自定义UI构建器生成自定义UI(简单小部件的布局).因此,用户可以在画布上堆叠小部件(大多数图像,但也包括TextViews和EditText),移动它们等等.必须将UI存储在数据库中以备将来使用.因此,应该有一些加载和扩充此UI的机制.这是主要问题.
我的第一个想法是依靠标准的Android布局机制.不幸的是,LayoutInflater使用编译成二进制形式的XML.据我所知,在运行时不可能将XML字符串编译成二进制表示.
有没有人有这种问题的经验?有什么建议?
我需要制作一个列表视图,左边有一个图像,该图像右侧有一个标题,下面有一个描述.我已经检查了文档中的列表视图,但我似乎无法找到这样的示例.我有一个XML定义的选项卡视图(根据android示例tabs1),列表视图作为第一个选项卡内容.但是我想通过RSS新闻源将内容添加到代码中的listview.
我正在考虑使用html注入字符串使用webview,但我如何从drawable文件夹中插入图像.(这些图像只是本地存储的"新闻图标",而不是来自互联网的图像)
对不起,如果这是一个小小的问题,但任何帮助赞赏:)
我有我attr.xml指定的自定义文档declare-styleable:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="EditTextValidateablePreference">
<attr name="errorMessage" format="reference" />
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)
然后在布局我设置:
<com.xx.yy.EditTextValidateablePreference
...
ns:errorMessage="@string/validation_email_mail_server_invalid"
/>
Run Code Online (Sandbox Code Playgroud)
在EditTextValidateablePreference.class我得到它:
String validatorErrorMessage = attrs.getAttributeValue(PREFERENCE_NS, "errorMessage");
Run Code Online (Sandbox Code Playgroud)
validatorErrorMessage 有一个像这样的值: @2131099700
如何获取其整数值以将其用于:
context.getResources().getString(messageId)
Run Code Online (Sandbox Code Playgroud)
?
谢谢 !
在我的Android布局中,我有一个TextView,它使用屏幕可用宽度的一半.在运行时,我将文本设置为(长)电子邮件地址.例如:
googleandroiddeveloper@gmail.com
Run Code Online (Sandbox Code Playgroud)
如果文本不适合一行,Android会插入换行符,这是所需的行为.但是,换行符的位置在第一个不适合该行的字符之前.结果可能是这样的:
googleandroiddeveloper@gmai
l.com
Run Code Online (Sandbox Code Playgroud)
我认为,这有点难看,特别是在电子邮件地址中.我希望换行符出现在@角色前面:
googleandroiddeveloper
@gmail.com
Run Code Online (Sandbox Code Playgroud)
当然,我可以添加一个\n在我的strings.xml.但是,电子邮件地址在每种情况下都会使用两行,即使它适合一行.
我已经认为我已经找到了在\u200B电子邮件地址中添加ZERO WIDTH SPACE()的解决方案.
<string name="email">googleandroiddeveloper\u200B@gmail.com</string>
Run Code Online (Sandbox Code Playgroud)
但除了标准空间之外,Android不会将特殊空格字符检测为可破坏空间,因此此时不会添加换行符.
由于我在应用程序的多个位置处理大量电子邮件地址,我正在寻找在@角色之前添加易碎和不可见空间的解决方案,因此如果不适合一行,Android将包装电子邮件地址.
我想这应该是一个相当容易回答的问题,如果你比我更了解XML布局.在使用match_parent layout_height 时,我似乎没有得到我想的.
我有一个带有android:orientation ="vertical"的LinearLayout根元素.在这个LinearLayout里面我想要三个元素: - TextView - ListView - TextView
对于TextViews,我设置了android:layout_height ="wrap_content",这样它们只会显示其显示内容所需的高度.问题是,我希望一个TextView位于窗体的顶部,另一个位于窗体底部,而ListView填充窗体上可用的任何空间.所以这是我的xml布局:
Run Code Online (Sandbox Code Playgroud)<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30sp" android:text="Top TextView" /> <ListView android:id="@+id/listView_Species" android:layout_width="match_parent" android:layout_height="match_parent" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30sp" android:text="Bottom TextView" />
但它不起作用.这就是我得到的.我已经选择了ListView,以便突出显示它.注意它是如何一直延伸到表单的底部,将底部的TextView从表单中推出.

当我将ListView的layout_height属性更改为某个固定值(如180dp)时,这就是表单的样子.我只是发布这个来证明底部的TextView在那里,但我仍然不知道如何将它固定到屏幕的底部,而ListView占用了剩余的空间,但在两个TextView之间.

提前致谢.
我想创建一个支持所有屏幕大小的XML布局.在XML中,第一个元素是ImageView第二个元素,TextView第三个元素是ButtonImage.所以TextView应该是所有设备(小型,中型,大型,xLarge等)的确切位置.
我怎样才能做到这一点?
这里的XML输出应该是这样的:
这是我为普通/中等布局创建的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/firstscreenimage" />
<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<EditText
android:id="@+id/campa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/textView3"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="My Current\n Campaign" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/relativeLayout2"
android:layout_alignParentLeft="true" >
<Button
android:id="@+id/button1"
android:layout_width="210dp"
android:layout_height="210dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/animation0" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1" …Run Code Online (Sandbox Code Playgroud) 我正在尝试遵循一个教程,假设如何添加一个浮动按钮,在教程中它说要将属性添加android:elevation到按钮xml,如下所示:
<ImageButton
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/editButton"
android:layout_gravity="center|right"
android:clickable="false"
android:background="@drawable/edit_grey"
android:layout_marginRight="1dp"
android:elevation="@dimen/elevation_low"/>
Run Code Online (Sandbox Code Playgroud)
但它不认识那个属性......我相信它与我的项目目标或sdk有关...有人可以帮助我吗?
在设置填充期间我遇到了一些奇怪的问题EditText.xml看起来像这样:
<EditText
android:layout_width="270dp"
android:layout_height="55dp"
android:ems="10"
android:id="@+id/etEmail"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:textColor="#FFFFFF"
android:hint="Or Use your Email"
android:inputType="textEmailAddress"
android:layout_alignLeft="@+id/textView6"
android:layout_alignStart="@+id/textView6"
android:textColorHint="#FFFFFF"
android:background="@drawable/line_white"
android:paddingLeft="16.5dp"
android:layout_marginTop="10dp"
android:paddingRight="2dp" />
Run Code Online (Sandbox Code Playgroud)
以下是Samsung Note 2(Android 5.0.1)的屏幕截图:

...和LG G3(Android 4.4.2):

如你所见,android:paddingLeft对LG不起作用.
可能是什么原因?
谢谢.
UPD: 布局边界(LG):

我正在使用一个应用程序,SurfaceView在用户定义的某些参数下绘制对象.我为应用程序创建了布局,其中包括页眉,页脚,输入(用户输入要绘制的参数)和自定义SurfaceView.
这是简化的布局:
<android.support.constraint.ConstraintLayout 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="match_parent">
<!-- Custom SurfaceView Layout -->
<org.firengine.myapp.CustomPreview
android:id="@+id/container_content"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- Header Layout: This is basically a Toolbar, with having a top padding of status bar height (see Note). -->
<FrameLayout
android:id="@+id/container_header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorTint"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">...</FrameLayout>
<!-- Footer Layout - This is just a container, with having a bottom padding of navigation bar height (see Note). -->
<FrameLayout
android:id="@+id/container_footer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorTint" …Run Code Online (Sandbox Code Playgroud) 最近,我已更新到Android Studio 3.5。我有三个视图:名为sample.xml文件的垂直LinearLayout(ViewGroup)中的EditText,TextView和Button。当我按ctrl + alt + L格式化内容时,所有视图都会自动重新排列。在我的情况下,位于底部的Button视图在格式化后已到达顶部,位于第一和第二顶部的EditText和TextView也分别在垂直LinearLayout中分别排在第二和第三位置。
Android Studio:3.5
Android Gradle插件:3.5.0
摇篮:5.4.1
JRE:1.8.0_202-release-1483-b03x64
作业系统:Windows 8.1(amd64)v6.3