视图以预览为中心但不在设备上
View centered on Preview but not on device
我正在向 activity 添加一个片段,它的布局非常简单:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:padding="16dp">
<Button
android:id="@+id/fragment_pay_request_pbutton"
style="@style/ButtonsStyle"
android:text="Pay" />
<Button
android:layout_marginTop="16dp"
android:id="@+id/fragment_pay_request_rbutton"
style="@style/ButtonsStyle"
android:layout_below="@id/fragment_pay_request_pbutton"
android:text="Request" />
<Button
android:layout_marginTop="16dp"
android:id="@+id/fragment_pay_request_bbutton"
style="@style/ButtonsStyle"
android:layout_below="@id/fragment_pay_request_rbutton"
android:text="Bills" />
</RelativeLayout>
预览时一切正常:
但在设备上:
我正在使用 Lolipop 5.1 和覆盖模式来测试布局。
有人知道为什么它不起作用以及我可以做些什么来解决这类问题。
顺便说一句:片段很简单:
/**
* Created by laurentmeyer on 15/03/15.
*/
public class PayOrRequestFragment extends BaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View toReturn = inflater.inflate(R.layout.fragment_pay_request, container, false);
Button pay = (Button) toReturn.findViewById(R.id.fragment_pay_request_pbutton);
Button request = (Button) toReturn.findViewById(R.id.fragment_pay_request_rbutton);
configureButton(request, pay);
return toReturn;
}
private void configureButton(Button request, Button pay) {
request.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] parameters = {"com.payment.laurentmeyer.mobilepayment.fragments.ReceiveFragment", "com.payment.laurentmeyer.mobilepayment.fragments.RequestMethodsFragment"};
mCallbacks.createSliderWithParameters(parameters);
}
});
pay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] parameters = {"com.payment.laurentmeyer.mobilepayment.fragments.SendFragment", "com.payment.laurentmeyer.mobilepayment.fragments.VerificationFragment"};
mCallbacks.createSliderWithParameters(parameters);
}
});
}
}
您必须将片段放入 Activity 中的视图容器中...您没有 post 您的 Activity 的布局。你的视图容器有android:layout_height="wrap_content"
吗?
我正在向 activity 添加一个片段,它的布局非常简单:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:padding="16dp">
<Button
android:id="@+id/fragment_pay_request_pbutton"
style="@style/ButtonsStyle"
android:text="Pay" />
<Button
android:layout_marginTop="16dp"
android:id="@+id/fragment_pay_request_rbutton"
style="@style/ButtonsStyle"
android:layout_below="@id/fragment_pay_request_pbutton"
android:text="Request" />
<Button
android:layout_marginTop="16dp"
android:id="@+id/fragment_pay_request_bbutton"
style="@style/ButtonsStyle"
android:layout_below="@id/fragment_pay_request_rbutton"
android:text="Bills" />
</RelativeLayout>
预览时一切正常:
但在设备上:
我正在使用 Lolipop 5.1 和覆盖模式来测试布局。
有人知道为什么它不起作用以及我可以做些什么来解决这类问题。
顺便说一句:片段很简单:
/**
* Created by laurentmeyer on 15/03/15.
*/
public class PayOrRequestFragment extends BaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View toReturn = inflater.inflate(R.layout.fragment_pay_request, container, false);
Button pay = (Button) toReturn.findViewById(R.id.fragment_pay_request_pbutton);
Button request = (Button) toReturn.findViewById(R.id.fragment_pay_request_rbutton);
configureButton(request, pay);
return toReturn;
}
private void configureButton(Button request, Button pay) {
request.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] parameters = {"com.payment.laurentmeyer.mobilepayment.fragments.ReceiveFragment", "com.payment.laurentmeyer.mobilepayment.fragments.RequestMethodsFragment"};
mCallbacks.createSliderWithParameters(parameters);
}
});
pay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] parameters = {"com.payment.laurentmeyer.mobilepayment.fragments.SendFragment", "com.payment.laurentmeyer.mobilepayment.fragments.VerificationFragment"};
mCallbacks.createSliderWithParameters(parameters);
}
});
}
}
您必须将片段放入 Activity 中的视图容器中...您没有 post 您的 Activity 的布局。你的视图容器有android:layout_height="wrap_content"
吗?