[英]How to convert web.xml code to java config for java melody
[英]How to convert xml positioning to java code?
我想以一種特定的方式顯示數據庫中所有可用的關系。 這是我在創作者中設計的。
我想顯示未定義數量的電影,所以我用Java生成了這部電影。 如何將xml定位轉換為Java? 使用哪個類? 這是xml文件:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="78dp"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Spectre (2015)"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Great Britain 2D Subtitles 121 min"
android:id="@+id/textView2"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="18:45"
android:id="@+id/textView3"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
這是Java代碼:
for (int i = 0; i < 20; i++) {
RelativeLayout relLayout = new RelativeLayout(this);
TextView textView = new TextView(this);
textView.setText("Big black text:" + i);
textView.setTextSize(22);
textView.setTextColor(Color.BLACK);
TextView textView1 = new TextView(this);
textView1.setText("Middle grey text:"+i);
textView1.setTextSize(18);
textView1.setTextColor(Color.GRAY);
TextView textView2 = new TextView(this);
textView2.setText("Right down corner:" + i);
textView2.setTextSize(20);
textView2.setTextColor(Color.BLACK);
relLayout.addView(textView);
relLayout.addView(textView1);
relLayout.addView(textView2);
relLayout.setId(i);
final int id_ = relLayout.getId();
LinearLayout layout = (LinearLayout) findViewById(R.id.llayout);
layout.addView(relLayout);
relLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Toast.makeText(getApplicationContext(),
"Button clicked index = " + id_, Toast.LENGTH_SHORT)
.show();
}
});
}
看看下面的課
您的方法是錯誤的,因為如果您有很多行,則該應用程序將完全崩潰。
當然,您需要自定義列表項,該列表項通常是您可以用谷歌搜索出來的熱門話題,但這是其中之一:
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.