im cố gắng Chức vụ nút của tôi không chính xác ở trung tâm, nhưng cho phép nói trong vòng 2/5s chiều cao màn hình, tôi đang tìm kiếm thuộc tính không thành công, vì vậy tôi đã cố gắng tiếp cận nàyCó cách nào để bù đắp chế độ xem từ trung tâm trong Android không?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:padding="20dp" >
<ImageButton
android:id="@+id/flashlight_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/fakeView"
android:background="@null"
android:contentDescription="@string/flashlight_button_description"
android:src="@drawable/freeml_bright" />
<View
android:id="@+id/fakeView"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_centerInParent="true"
android:background="#FFAABB" />
</RelativeLayout>
tuy nhiên nó không hoạt động , ngay cả khi tôi đặt lề trên giao diện giả.
Bất kỳ ý tưởng nào?
// EDIT //
nhờ cho bạn câu trả lời guys, thuộc tính đệm hoạt động, tuy nhiên vì nó là một hình ảnh lớn và nếu tôi muốn nó bắt đầu từ 2/5ths chiều cao màn hình, nó bao gồm các điểm trung tâm của màn hình, vì vậy nếu tôi sử dụng thuộc tính padding nó hoạt động nhưng nó đẩy nó ra khỏi trung tâm và không cho phép nó để trang trải nó. Tuy nhiên, tôi đã làm cho nó hoạt động bằng cách sử dụng bố cục tuyến tính, mà tôi muốn tránh vì có nhiều chế độ xem ở trên và dưới cạnh nhau để nó có thể dẫn đến chế độ xem lồng nhau bằng bố cục tuyến tính. Thật không may tôi nghĩ rằng nó là lựa chọn duy nhất.
Nó về cơ bản nó sử dụng một bố trí tuyến tính lấp đầy không gian còn lại chưa sử dụng bởi quan điểm trên và dưới với height = 0dp và trọng lượng = 1 và đặt trọng lực của nó để tập trung
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/application_logo_description"
android:src="@drawable/mylight" />
<ImageButton
android:id="@+id/settings_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:contentDescription="@string/settings_button_description"
android:src="@drawable/settings_button" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="@+id/flashlight_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:contentDescription="@string/flashlight_button_description"
android:src="@drawable/flashlight_button_selector" />
<View
android:id="@+id/fakeView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="60dp"
android:background="#FFAABB" />
</LinearLayout>
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:contentDescription="@string/powered_by_description"
android:src="@drawable/powered_by" />
<ImageButton
android:id="@+id/ad_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="@null"
android:contentDescription="@string/ad_button_description"
android:src="@drawable/freeml" />
</LinearLayout>
Cảm ơn thông tin của bạn.
Hi, nó hoạt động, tuy nhiên như tôi có thể có đánh lừa bạn, + Nhà mình một hình ảnh khá lớn trong ImageButton, vì vậy nếu tôi muốn để có nó bắt đầu trong 2/5s chiều cao màn hình, do đó nó bao gồm các điểm trung tâm của màn hình. NẾU tôi sử dụng câu trả lời được đề xuất của bạn, nó sẽ đẩy nút ra xa trung tâm và không cho phép nó che đậy nó. – urSus
Hmm, có thể thử thay thế paddingTop bằng paddingBottom? –
Oh tôi thực sự đọc nó sai, thiết lập padding trên trung tâm giả xem không làm việc ở tất cả. Thiết lập padding trên nút ở trên nó chỉ đẩy nút lên trên mà không phải là giải pháp cho tôi vì tôi muốn nó để trang trải các điểm giữa – urSus