text简单的片段(代码片段)

author author     2022-12-02     503

关键词:

<ScrollView
    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"
    tools:context="com.example.android.android_me.ui.AndroidMeActivity">

    <!-- LinearLayout for holding three Android-Me images -->
    <LinearLayout
        android:id="@+id/android_me_linear_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">


        <!-- This container holds the head BodyPartFragment of the custom Android-Me image -->
        <FrameLayout android:id="@+id/head_container"
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:scaleType="centerInside"/>


    </LinearLayout>

</ScrollView>
package com.example.android.android_me.ui;

import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.example.android.android_me.R;

// This activity will display a custom Android image composed of three body parts: head, body, and legs
public class AndroidMeActivity extends AppCompatActivity 


    @Override
    protected void onCreate(Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_android_me);

        // Create a new head BodyPartFragment
        BodyPartFragment headFragment = new BodyPartFragment();

        // Add the fragment to its container using a FragmentManager and a Transaction
        FragmentManager fragmentManager = getSupportFragmentManager();

        fragmentManager.beginTransaction()
                .add(R.id.head_container, headFragment)
                .commit();
    
1. Create a fragment layout
2. Create a class that extends Fragment
3. Inflate the view 
4. Add fragment to the main layout file
5. Bind object of the fragment class in the main activity
package com.example.android.android_me.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.android.android_me.R;
import com.example.android.android_me.data.AndroidImageAssets;

public class BodyPartFragment extends Fragment 

    /**
     * Mandatory empty constructor for the fragment manager to instantiate the fragment
     */
    public BodyPartFragment() 
    

    /**
     * Inflates the fragment layout file and sets the correct resource for the image to display
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 

        // Inflate the Android-Me fragment layout
        View rootView = inflater.inflate(R.layout.fragment_body_part, container, false);

        // Get a reference to the ImageView in the fragment layout
        ImageView imageView = (ImageView) rootView.findViewById(R.id.body_part_image_view);

        // Set the image to the first in our list of head images
        imageView.setImageResource(AndroidImageAssets.getHeads().get(0));

        // Return the rootView
        return rootView;
    

<?xml version="1.0" encoding="utf-8"?>
<!-- This fragment layout displays just one image of an Android-Me body part -->
<ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/body_part_image_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</ImageView>

text简单的饼干操作(代码片段)

查看详情

text简单模式的标记(代码片段)

查看详情

text简单的cssdotleaders(代码片段)

查看详情

text简单的猫命令(代码片段)

查看详情

text简单的手风琴(代码片段)

查看详情

text超级简单的cssdropcap(代码片段)

查看详情

text简单的系统alertdialog(代码片段)

查看详情

text使用简单的jquery评级星(代码片段)

查看详情

text简单的css媒体查询-移动优先(代码片段)

查看详情

text非常简单的html电子邮件(代码片段)

查看详情

text用于raspberripi相机的简单mjpeg流光(代码片段)

查看详情

text我简单的mysql命令行cheatsheet(代码片段)

查看详情

text我简单的mysql命令行cheatsheet(代码片段)

查看详情

text我简单的mysql命令行cheatsheet(代码片段)

查看详情

text我简单的mysql命令行cheatsheet(代码片段)

查看详情

text教程:创建一个简单的管道(codecommit存储库)(代码片段)

查看详情

text带有dockerpost命令的awsec2简单ami(代码片段)

查看详情

text一个简单的solidity程序,带有getters和setter(代码片段)

查看详情