[英]NavigationDrawer Fragment Header image
我将图像放在导航抽屉中,但看不到。
这是我的activity_main.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<LinearLayout
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:src="@drawable/ocio"
android:layout_gravity="left|center_vertical" />
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="otcproject.v1.navigationdrawer.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
这是我的MainActivity
public class MainActivity extends FragmentActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
该应用程序运行,我可以看到选项NavigationDrawer,但看不到图像标题。
问题是片段的match_parent
。 尝试将其高度设置为0dp,将权重设置为1(它将占据所有可用空间,与“ match_parent
减去ImageView的高度”相同)。
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="start"
android:name="otcproject.v1.navigationdrawer.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />
match_parent
表示该视图将匹配其父视图的大小,因此您不能拥有一个包装其内容的视图(ImageView)和一个与其父视图匹配的视图(片段)。 第二个将与第一个重叠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.