我可以从 ORM(Cupboard)中获取 POJO,但我不知道如何编写 xml 来绑定到这样的列表。除了非常简短地提到在 ListView 或 RecyclerView 中使用它们之外,所有示例都是单一的。因此,我尝试在 xml 文件中使用单一绑定,并为每个项目再次“膨胀”。该代码如下:
private void listThings() {
LinearLayout gList = (LinearLayout) findViewById(R.id.thingList);
gList.removeAllViews();
SQLiteDatabase db = new CGDatabaseHandler(gList.getContext()).getReadableDatabase();
DatabaseCompartment dbc = cupboard().withDatabase(db);
QueryResultIterable<Thing> itr = null;
try {
itr = dbc.query(Thing.class).query();
for (Thing thing : itr) {
// use data binding to create a UI widget for each
LayoutInflater inflater = (LayoutInflater) getBaseContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ThingDocumentLabelBinding binding = DataBindingUtil.inflate(inflater,
R.layout.thing_document_label, gList, false);
binding.setThing(thing);
//
gList.addView(binding.getRoot());
}
} finally {
// close …Run Code Online (Sandbox Code Playgroud) 我想在 android 按钮中遵循以下功能:
单击时按钮应改变颜色
一些特定的按钮具有诸如按钮的背景颜色应保持更改的功能,直到我们按下另一个按钮。
我读过有关tools:context 的内容,发现它在开发时非常有用,因为它可以帮助我了解我使用了当前 Xml 的哪些活动。
我的问题是:
我有 2 个活动,使用相同的 Xml 文件(重复使用相同的layout.xml文件),但我无法使用tools:context
如何
tools:context在 Xml 中使用链接 2 个活动?
我努力了:
<?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="match_parent"
android:layout_height="wrap_content"
tools:context="com.example.mytestapp.MainActivity,com.example.mytestapp.Main2Activity">
<!-- Other Layouts Here -->
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这给了我红线
还尝试使用:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:tools2="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.example.mytestapp.MainActivity"
tools2:context="com.example.mytestapp.Main2Activity">
<!-- Other Layouts Here -->
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这不会给出红线,但是当我运行它们时,我收到以下错误:
Error:(2) error: duplicate attribute.
Error:(2) duplicate attribute.
Run Code Online (Sandbox Code Playgroud) 我开始使用Fedor的ListView实现.这是我的ListView项的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="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="50dip"
android:layout_height="50dip" android:src="@drawable/stub" android:scaleType="centerCrop"/>
<TextView
android:id="@+id/name"
android:layout_width="0px"
android:layout_height="0px"
android:layout_weight="0" android:textSize="20dip" android:layout_marginLeft="10dip"/>
<TextView
android:id="@+id/address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" android:textSize="16dip" android:layout_marginLeft="10dip"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我在设备上看到的是ImageView和从左到右依次显示的两个TextView.
我想要的是右边的ImageView(这已经是正确的),imageview右侧的TextView名称(这是正确的),地址TextView,名称为TextView.我无法弄清楚如何正确布局.
请注意,我知道我可以在名称中添加一个新行,并在此之后包含地址文本,但我希望这两个元素具有不同的字体大小,因此这不是一个选项.非常感谢!
style="?android:attr/starStyle"
Run Code Online (Sandbox Code Playgroud)
将此代码应用于复选框属性后,我无法查看该复选框.代码中是否有错误?
我正在eclipse中开发一个android应用程序.我有一组按钮,我想在它们之间插入一些空格.我正在使用drawable中的xml文件(background.xml)设置这些按钮的背景.对于插入空格,我使用以下代码行来处理主xml文件中的所有按钮seperatley.
android:layout_marginLeft = "10dip"
android:layout_marginRight = "10dip"
android:layout_marginTop = "10dip"
android:layout_marginBottom = "10dip"
Run Code Online (Sandbox Code Playgroud)
我的问题是,有没有办法通过修改background.xml文件来设置边距.否则,每当我修改边距时,我都必须编辑所有按钮.提前致谢.
我有两个按钮,我想把它们水平放置,因此它们将在屏幕上彼此相邻,没有空间,我知道我可以用线性布局和设置重量做但我想要相对布局因为我已经在我的XML中有重量所以将两个权重放在一起会是不好的表现.
我试过这样的
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_selector" >
<Button
android:id="@+id/b_orderMeal_send"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:background="@drawable/button_selector"
android:clickable="true"
android:focusable="true"
android:text="@string/b_send"
android:textColor="#FFFFFF" />
<Button
android:id="@+id/b_orderMeal_cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:background="@drawable/button_selector"
android:clickable="true"
android:focusable="true"
android:text="@string/b_cancel"
android:textColor="#FFFFFF" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
但只是取消按钮出现,这是因为我使用"填充父",请问有什么解决方案?
我试图通过WebView在一些示例中使用和格式化带有HTML的String资源来证明文本是正确的:
<string name="dTxt">
<html>
<head></head>
<bodystyle text-align:justify=""><body> Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nunc pellentesque, urna nec hendrerit pellentesque, risus massa </body>
</bodystyle>
</html>
</string>
Run Code Online (Sandbox Code Playgroud)
ADT拒绝解析Strings文档,但有以下错误:
W/ResourceType( 2612): Bad XML block: header size 296 or total size 6144712 is larger than data size 0
Run Code Online (Sandbox Code Playgroud)
这有什么不对?
我想绘制一个完美的圆形按钮.我尝试使用以下代码:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<stroke
android:width="3dip"
android:color="#065a32" />
<corners android:radius="10dip"/>
<solid android:color="#eaebec" />
</shape>
Run Code Online (Sandbox Code Playgroud)
但即使我更改参数,我也只能绘制椭圆形状:
<stroke
android:width="3dip"/>
<corners android:radius="10dip"/>
Run Code Online (Sandbox Code Playgroud)
我的截图:

我已经尝试过这个网站的不同链接,但没有一个满足我的需要.
编辑:
我的getView()代码是:
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (convertView == null) {
LayoutInflater vi = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.calendar_item, null);
}
view.setBackgroundResource(R.drawable.calendar_cell_clicked);
}
Run Code Online (Sandbox Code Playgroud) 我有一个Web平台,可以存储我正在构建的应用程序的数据.Web平台使用Ruby on Rails构建,主应用程序适用于Android.我很想知道将我的数据存储在XML文件中的任何性能问题(对于Android应用程序).最终我的网络应用程序中的数据库将有大约2000个条目(如文章/文章类别 - >文章 - 内容,描述,标题,图像路径).
使用SQLite或XML文件来存储我的数据是否更好?
android-xml ×10
android ×9
xml ×2
checkbox ×1
data-storage ×1
java ×1
margins ×1
mvvm ×1
styles ×1