Tôi đang gặp một số vấn đề khi nhận hai con của số LinearLayout
để có cùng chiều rộng. Đây là những gì tôi nhận được:LinearLayout với hai con có chiều rộng bằng nhau
Và đây là xml bố trí của tôi cho các hộp màu xám:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:background="@color/medium_grey"
>
<ImageView
android:id="@+id/profile_photo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/placeholder_profile_photo"
android:scaleType="fitCenter"
android:contentDescription="@string/blank"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:background="@color/alert"
>
<TextView
android:id="@+id/profile_rate_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Rate User"
/>
<LinearLayout
android:id="@+id/profile_action_rate_user"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:id="@+id/profile_action_rate_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/user_rate_up"
/>
<ImageView
android:id="@+id/profile_action_rate_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/user_rate_down"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
tôi đã giả định rằng thiết lập layout_weight
của con cái gốc LinearLayout
cùng với a weightSum
và chiều rộng 0dp
sẽ tạo ra hiệu ứng mong muốn (hình ảnh có cùng kích thước với phần 'tỷ lệ người dùng' màu hồng) tuy nhiên đây không phải là trường hợp.
Tôi đang thiếu gì?
Edit:
Đây là những gì tôi muốn nó trông giống như
Bức ảnh và cách bố trí tuyến tính màu hồng nên độ rộng bằng nhau.
tôi đã không nhận được sự cố hoàn chỉnh của bạn @ boz.plz cho biết, đầu ra mong muốn của bạn là gì ??? tôi có thể giải quyết vấn đề cân nặng của bạn. tôi nghĩ bạn nên sử dụng trọng lượng được sắp xếp của weightSum. – Rumit
@Rumit Tôi đã thêm một số thông tin khác – boz
có thể trùng lặp của [Android: Làm thế nào để làm cho tất cả các yếu tố bên trong LinearLayout cùng kích thước?] (Http://stackoverflow.com/questions/1177020/android-how-to-make-all- các yếu tố-bên trong-linearlayout-cùng kích thước) –