android - Layout display so wrongly
问题描述
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();
}
解决方案
对于 a RelativeLayout
,您指定某个元素应与其父元素的顶部对齐android:layout_alignParentTop="true"
。
所以,使用:
<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" />
推荐阅读
- c++ - 为什么 getline() 函数在这里不起作用?
- c# - 发布后如何更改使用红隼运行的 Asp 核心 Web 应用程序的 IP 和端口号?
- angular - Angular - 如何从我的服务组件中的订阅返回布尔值?
- javascript - IPAD 上不显示视频
- r - 防止 Shiny selectInput 在更新反应图时过早评估
- javascript - 如何在 React.JS 中通过 className 使元素消失?
- xml - 根据 XSD 中的其他字段值定义要求字段
- java - Runtime.exec() 是否仅适用于某些命令?
- javascript - Handlebar 在控制台中返回空数据
- javascript - 将事件处理程序绑定到 React ref