[英]ImageView is stretch when not supposed to be - Android
列0應該是紅色x或綠色復選標記的圖片。 出於測試目的,我僅在第1行放置了一個圖像。如下圖所示,紅色的x圖像很長並且呈矩形展開。 我希望它是一個小的正方形圖像。 即使我將layout_width和layout_height分別設置為50dp,10dp或代碼如下所示,該圖像似乎也與下面顯示的圖像相同。 圖片的尺寸為100x100 PNG圖片-如果這樣的話。
我的問題是為什么圖像要拉伸,如何將其制作成小正方形圖像。 預先感謝您的幫助!
結果.java
ImageView q1Image = (ImageView)findViewById(R.id.q1Image);
q1Image.setScaleType(ImageView.ScaleType.FIT_CENTER);
resultsmain.xml
<TableRow
android:id="@+id/row4"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:stretchColumns="0,1,2,3"
android:layout_weight="1" >
<ImageView
android:id="@+id/q1Image"
android:layout_width="5dp"
android:layout_height="10dp"
android:layout_weight=".1" />
<TextView
android:id="@+id/q1Question"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:textSize="8sp" />
<TextView
android:id="@+id/q1Answer"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:textSize="8sp"
android:gravity="center_horizontal" />
<TextView
android:id="@+id/q1Verse"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:textSize="8sp"
android:gravity="center_horizontal" />
</TableRow>
嘗試這個:
<TableRow
android:id="@+id/row4"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:stretchColumns="0,1,2,3"
android:weightSum="1" >
<ImageView
android:id="@+id/q1Image"
android:layout_width="5dp"
android:layout_height="10dp"
android:layout_weight=".1"
/>
<TextView
android:id="@+id/q1Question"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:textSize="8sp" />
<TextView
android:id="@+id/q1Answer"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:textSize="8sp"
android:gravity="center_horizontal" />
<TextView
android:id="@+id/q1Verse"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:textSize="8sp"
android:gravity="center_horizontal" />
</TableRow>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.