如何在Android中正确设置URL图像?

如何在Android中正确设置URL图像?,android,image,Android,Image,我是android新手,我正在尝试在主屏幕上打开URL图像。我的问题是,我使用的导航抽屉也在我的主页上。一切正常,只有来自数据库的主图像稍微向上,而我复制的示例中的图像看起来非常完美 我不知道为什么我的形象在上升。图像的渲染应如下所示: 我的图像呈现如下: 这是我的FragmentOne.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.androi

我是android新手,我正在尝试在主屏幕上打开URL图像。我的问题是,我使用的导航抽屉也在我的主页上。一切正常,只有来自数据库的主图像稍微向上,而我复制的示例中的图像看起来非常完美

我不知道为什么我的形象在上升。图像的渲染应如下所示:

我的图像呈现如下:

这是我的FragmentOne.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.7">

            <ImageView
                android:id="@+id/ms1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:adjustViewBounds="true"
                android:src="@mipmap/ic_launcher" />


        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.3">


            <ImageView
                android:id="@+id/ms2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:src="@mipmap/ic_launcher" />

            <ImageView
                android:id="@+id/ms3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:src="@mipmap/ic_launcher" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>
我的FragmentOne.java

public class FragmentOne extends Fragment
{
    Activity activity;

    View rootView;

    ImageView im1, im2, im3;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
    {
        rootView = inflater.inflate(R.layout.fragment_one, container, false);

        activity = getActivity();

        im1 = (ImageView)rootView.findViewById(R.id.ms1);
        im2 = (ImageView)rootView.findViewById(R.id.ms2);

        im2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(getActivity(), Login.class);
                startActivity(intent);
            }
        });






        im3 = (ImageView)rootView.findViewById(R.id.ms3);

        Picasso.with(activity).load("http://i.imgur.com/DvpvklR.png").into(im1);
        Picasso.with(activity).load("https://api.learn2crack.com/android/images/donut.png").into(im2);
        Picasso.with(activity).load("http://hdwallpaperbackgrounds.net/wp-content/uploads/2016/07/hd-nature-wallpapers.jpg").into(im3);

        return rootView;
    }
}

我试着进行调试,但也没有用,这是一个非常奇怪的问题。

问题发生在主内容xml上。在主要活动xml中使用图像时,图像将被切断。使用这个技巧,它会起作用的。简单地将边距放在主内容上方

<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <FrameLayout
        android:layout_marginTop="?actionBarSize"
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </FrameLayout>
</RelativeLayout>


在MainActivity中,您应该将活动no扩展为AppCompative。AppCompatActivity显示一个栏

您必须在布局中包括一个自定义操作栏


请点击链接。通过代码快照和深度,可以很好地解释这一点。:)

但是我复制的示例..在这个示例中,也没有选择任何操作栏是的,您必须使用您想要的自定义工具栏。在布局中包括工具栏。我想会有用的。我该怎么办?你能帮我编码吗?哪种布局..我必须包括工具栏?我想这个链接将有助于你想要的实现:但是这个例子被复制了..也使用了app compat活动..我复制了同样的例子..因为一切都很完美
public class FragmentOne extends Fragment
{
    Activity activity;

    View rootView;

    ImageView im1, im2, im3;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
    {
        rootView = inflater.inflate(R.layout.fragment_one, container, false);

        activity = getActivity();

        im1 = (ImageView)rootView.findViewById(R.id.ms1);
        im2 = (ImageView)rootView.findViewById(R.id.ms2);

        im2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(getActivity(), Login.class);
                startActivity(intent);
            }
        });






        im3 = (ImageView)rootView.findViewById(R.id.ms3);

        Picasso.with(activity).load("http://i.imgur.com/DvpvklR.png").into(im1);
        Picasso.with(activity).load("https://api.learn2crack.com/android/images/donut.png").into(im2);
        Picasso.with(activity).load("http://hdwallpaperbackgrounds.net/wp-content/uploads/2016/07/hd-nature-wallpapers.jpg").into(im3);

        return rootView;
    }
}
<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <FrameLayout
        android:layout_marginTop="?actionBarSize"
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </FrameLayout>
</RelativeLayout>