Reputation: 193
The layout will all move down in the display ,as if the view should be on the top,but i run it on AVD and it moves down to the bottom,so there's a whole blank area on top of that It's just this layout and any other layout is fine . I don't know why it happens .But i think the reason it's either XML or JAVA.
(I use a layout to open this layout and it's in fragment )
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView6"
android:layout_width="150dp"
android:layout_height="150dp"
android:contentDescription="@string/todo"
android:src="@drawable/layout" />
</RelativeLayout>
JAVA
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
tranView = inflater.inflate(R.layout.setting,container,false);
LinearLayout app_layer = (LinearLayout) tranView.findViewById(R.id.layout);
app_layer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Fragment fragment = null;
switch (view.getId()) {
case R.id.layout:
fragment = new Page_Aboutus();
replaceFragment(fragment);
break;
}
}
});
return tranView;
}
public void replaceFragment(Fragment somefragment) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, somefragment);
transaction.addToBackStack(null);
transaction.commit();
}
Upvotes: 1
Views: 108
Reputation: 8231
For a RelativeLayout
, you specify that a certain element should align itself with the top of its parent with android:layout_alignParentTop="true"
.
So, use:
<ImageView
android:id="@+id/imageView6"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:contentDescription="@string/todo"
android:src="@drawable/layout" />
Upvotes: 2