ビューを何度も展開しようとしています。 私のビューは1つのイメージビューとその下のテキストビューで構成され、特定の位置に配置します。以下は複数のビューを作成する
私は複数回膨らませています私のitem.xmlである:ここでは
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="100dp"
android:background="@android:color/holo_blue_dark"
android:layout_height="100dp">
<ImageView
android:layout_gravity="center"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@mipmap/ic_launcher"
android:id="@+id/imageView"/>
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="20dp"
android:textSize="12sp"
android:textStyle="bold"
android:text="Large Text"
android:id="@+id/textView" />
</LinearLayout>
がインフレートと私のコードです:
for (int i = 0; i < 1; i++) {
final View v = linf.inflate(R.layout.item, null);
TextView tvs = (TextView) v.findViewById(R.id.textView);
ImageView ivs = (ImageView) v.findViewById(R.id.imageView);
tvs.setText(i+"");
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100, 100);
int w = (mWidth/2)-50;
int h =(mHeight/2)-50;
params.leftMargin = w;
params.topMargin = h;
Log.e("W-H", mWidth + "-" + mHeight);
rr.addView(v,params);
}
私はitem.xmlを配置することができますよが正常にフィットしていますが、画面が正しく表示されません。高さと幅を100dpに固定しました。ここで
は私が here
'私は高さを設定し、固定幅いる本当にない100dp.'。この 'RelativeLayout.LayoutParams params =新しいRelativeLayout.LayoutParams(100,100);は**ピクセル**、** dp ** sではありません –