đây bạn là vấn đề của tôi: Tôi muốn làm một bố cục trông giống như lưới này trong android:TableLayout và nút Android thay đổi kích thước
Để làm như vậy, tôi đã tạo bố trí này:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3">
<Button
android:id="@+id/clientimain"
android:layout_width="0dip"
android:layout_weight="1" android:layout_height="fill_parent"/>
<Button
android:id="@+id/button1"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3" >
<Button
android:id="@+id/button2"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button"/>
<Button
android:id="@+id/button6"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3" >
<Button
android:id="@+id/button3"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button"
/>
<Button
android:id="@+id/button7"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button"
/>
</TableRow>
</TableLayout>
</RelativeLayout>
Vì vậy, về cơ bản nó được tạo thành bởi 6 nút trong bố cục bảng với thuộc tính trọng số được đặt chính xác (hoặc tôi hy vọng như vậy!). Kết quả có vẻ tốt cho đến khi tôi sẽ cố gắng thiết lập thuộc tính nền của mỗi nút. Trong trường hợp đó, nút sẽ lấy chiều cao của hình ảnh được đặt vào (chiều rộng là ok). Ví dụ nếu tôi đặt hình nền có kích thước là x 96px x x 96px kết quả giống như thế này:
Có cách nào để ngăn chặn nút này "căng" và để tập trung một cách chính xác hình ảnh? Tôi đã cố thay đổi thuộc tính chiều cao cho mỗi hàng trong bảng, để thay đổi thuộc tính chiều cao tối đa của nút và cũng có thể thay đổi loại nút bằng nút hình ảnh (và đặt thuộc tính src với biểu tượng mong muốn) nhưng tôi không hoàn thành kết quả.
Tôi cũng đã làm tài liệu google về hỗ trợ nhiều màn hình và về từng bố cục cơ bản nhưng tôi không tìm thấy bất kỳ giải pháp nào. Cảm ơn trước bất kỳ ai muốn giúp tôi!
Andrea
thử và sử dụng android: scaleType = "fitXY" trên nút của bạn. cũng thử và sử dụng http://developer.android.com/resources/tutorials/views/hello-gridview.html cho tác vụ này –
Tôi đã thử thuộc tính android: scaleType = "fitXY" nhưng nó không hoạt động. Tôi sẽ cố gắng chuyển sang bố cục lưới nếu tôi không thể tìm thấy giải pháp. Cảm ơn – jiraya85