我一直在为此工作了几天。我想要做的就是将存储在SD卡上的图像放入片段内的ImageView中。ImageView未显示在片段中
我用这个教程的抽屉式导航栏布局: http://developer.android.com/training/implementing-navigation/nav-drawer.html
而这一次为更深入地执行: hxxp://www.androidbegin.com/tutorial/implementing-actionbarsherlock-side-menu-navigation -drawer功能于机器人/
这是fragment1.xml:
<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" >
<ImageView
android:id="@+id/workingimageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<!--
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/Fragment1"
android:id="@+id/textview1" />
-->
</RelativeLayout>
这是包含内容和抽屉导航的XML:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Slideout Menü -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111" />
</android.support.v4.widget.DrawerLayout>
这是onCreateView源代码中的片段:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment1, container, false);
/** Load temporary image */
/** Check if folder exists first */
if(checkForWorkingDirectory())
{
workingImageView = (ImageView)
rootView.findViewById(R.id.workingimageview);
workingImageView.setImageBitmap(scaleImage.decodeSampledBitmapFromResource(returnAbsoluteFilePath(),100,100));
}
return rootView;
//return inflater.inflate(R.layout.fragment1, null);
}
checkForWorkingDirectory()基本上查找该图像位于 和returnAbsoluteFilePath()的目录是不言而喻的:)
的ImageView完全不显示。但是,如果我将ImageView注释掉,并且只显示TextView,则文本显示得很好。
我也试过这个,因为当我加载图像我不那时知道的ImageView的尺寸: http://adanware.blogspot.de/2012/06/android-getting-measuring-fragment.html
这些教程立足我用什么来显示里面的一个ImageView的最好的和正确的方法分段?
如果您需要更多的代码或信息,请告诉我。 在此先感谢!
你是如何为ImageView的设置 “SRC”?你可以分享该代码吗? –
编辑;;)值“100”,“100”只是一个例子。他们应该以某种方式读取,以适应包含片段的整个可用大小。 – cgew85