如何使用ScrollView设置操作工具栏?

时间:2017-03-23 13:32:06

标签: android android-layout

我有列表视图的项目。当我进入其中一个列表菜单时,它会打开一个Activity,问题是Activity布局填充了ScrollView,我也希望显示一个操作栏,但是在我放置了widget工具栏之后它就像这样

enter image description here

并没有显示任何内容。

这是我使用滚动bview的活动布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:background="#ff00606d"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:id="@+id/toolbar2"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:titleTextAppearance="@style/Toolbar.TitleText"
        app:title="Light"
        app:titleTextColor="#ffffff">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageButton
                android:id="@+id/btn_back"
                android:layout_width="50px"
                android:layout_height="50px"
                android:layout_alignParentLeft="true"
                android:background="@android:color/transparent"
                android:src="@mipmap/ic_previous" />

            <TextView
                android:id="@+id/txt_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="16dp"
                android:layout_marginStart="16dp"
                android:layout_toEndOf="@+id/btn_back"
                android:layout_toRightOf="@+id/btn_back"
                android:text="Title"
                android:textColor="@android:color/white"
                android:textSize="16sp"
                android:textStyle="bold" />

        </RelativeLayout>
    </android.support.v7.widget.Toolbar>
    <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content">
        <LinearLayout android:orientation="vertical" android:padding="5.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <LinearLayout android:orientation="vertical" android:background="@drawable/round_corners_blue" android:padding="10.0dip" android:paddingTop="30.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20.0dip">
                <TextView android:textSize="20.0sp" android:textColor="#ff000000" android:gravity="center" android:background="@drawable/round_corners_bluesky" android:clickable="false" android:layout_width="fill_parent" android:layout_height="45.0dip" android:text="1-Incandescent " />
                <ImageView android:background="@drawable/lamp1" android:padding="10.0dip" android:clickable="false" android:layout_width="fill_parent" android:layout_height="240.0dip" android:layout_marginTop="5.0dip" android:scaleType="fitXY" />
                <TextView android:textSize="12.0sp" android:textColor="#ff000000" android:background="@drawable/round_corners_white" android:padding="10.0dip" android:clickable="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:layout_marginBottom="10.0dip" android:text="An incandescent light bulb, incandescent lamp or incandescent light globe is an electric light which produces light with a wire filament heated to a high temperature by an electric current passing through it, until it glows (see Incandescence). The hot filament is protected from oxidation with a glass or quartz bulb that is filled with inert gas or evacuated. In a halogen lamp, filament evaporation is prevented by a chemical process that redeposits metal vapor onto the filament, extending its life. The light bulb is supplied with electric current by feed-through terminals or wires embedded in the glass. Most bulbs are used in a socket which provides mechanical support and electrical connections. " />
            </LinearLayout>
            <LinearLayout android:orientation="vertical" android:background="@drawable/round_corners_blue" android:padding="10.0dip" android:paddingTop="30.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20.0dip">
                <TextView android:textSize="20.0sp" android:textColor="#ff000000" android:gravity="center" android:background="@drawable/round_corners_bluesky" android:clickable="false" android:layout_width="fill_parent" android:layout_height="45.0dip" android:text="2-Tungsten Halogen " />
                <ImageView android:background="@drawable/lamp2" android:clickable="false" android:layout_width="fill_parent" android:layout_height="240.0dip" android:layout_marginTop="5.0dip" android:scaleType="fitXY" />
                <TextView android:textSize="12.0sp" android:textColor="#ff000000" android:background="@drawable/round_corners_white" android:padding="10.0dip" android:clickable="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:layout_marginBottom="10.0dip" android:text="A halogen lamp, also known as a tungsten halogen, quartz-halogen or quartz iodine lamp, is an incandescent lamp that has a small amount of a halogen such as iodine or bromine added. The combination of the halogen gas and the tungsten filament produces a halogen cycle chemical reaction which redeposits evaporated tungsten back onto the filament, increasing its life and maintaining the clarity of the envelope. Because of this, a halogen lamp can be operated at a higher temperature than a standard gas-filled lamp of similar power and operating life, producing light of a higher luminous efficacy and color temperature. The small size of halogen lamps permits their use in compact optical systems for projectors and illumination." />
            </LinearLayout>
            <LinearLayout android:orientation="vertical" android:background="@drawable/round_corners_blue" android:padding="10.0dip" android:paddingTop="20.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20.0dip">
                <TextView android:textSize="20.0sp" android:textColor="#ff000000" android:gravity="center" android:background="@drawable/round_corners_bluesky" android:clickable="false" android:layout_width="fill_parent" android:layout_height="45.0dip" android:text="3-Low Pressure Mercury" />
                <ImageView android:background="@drawable/lamp3" android:clickable="false" android:layout_width="fill_parent" android:layout_height="240.0dip" android:layout_marginTop="5.0dip" android:scaleType="fitXY" />
                <TextView android:textSize="12.0sp" android:textColor="#ff000000" android:background="@drawable/round_corners_white" android:padding="10.0dip" android:clickable="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:layout_marginBottom="10.0dip" android:text="A low-pressure mercury lamp (LP Hg lamp) is a highly efficient UV light source of short wavelength.Classified as in the same group as fluorescent lamps or germicidal lamps, the main light emission is a 254nm line comprising an 185nm line of far shorter wavelength. Quite unlike LP mercury lamps, the high-pressure mercury lamps (HP Hg lamp) irradiate lights of many wavelengths including a visible light." />
            </LinearLayout>
            <LinearLayout android:orientation="vertical" android:background="@drawable/round_corners_blue" android:padding="10.0dip" android:paddingTop="20.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20.0dip">
                <TextView android:textSize="20.0sp" android:textColor="#ff000000" android:gravity="center" android:background="@drawable/round_corners_bluesky" android:clickable="false" android:layout_width="fill_parent" android:layout_height="45.0dip" android:text="4-High Pressure Mercury " />
                <ImageView android:background="@drawable/lamp4" android:clickable="false" android:layout_width="fill_parent" android:layout_height="240.0dip" android:layout_marginTop="5.0dip" android:scaleType="fitXY" />
                <TextView android:textSize="12.0sp" android:textColor="#ff000000" android:background="@drawable/round_corners_white" android:padding="10.0dip" android:clickable="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:layout_marginBottom="10.0dip" android:text="High-pressure discharge lamps generate a very large quantity of light in a very small space due to arc discharge. Exterior illumination for all kinds of traffic installations, stadiums, construction sites and buildings almost only use this type of lamp, and they are also often used for indoor lighting in industrial and sports complexes, sales rooms, foyers and trade fair booths. These lamps cover a wide range of applications depending on the type of burner used inside the lamp – sodium vapour, mercury vapour, or halogen metal vapour – from economical street lighting right down to design illumination. Their high light yield means that they are the most economical artificial light sources you will find anywhere. " />/> </LinearLayout>
            <LinearLayout android:orientation="vertical" android:background="@drawable/round_corners_blue" android:padding="10.0dip" android:paddingTop="20.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20.0dip">
                <TextView android:textSize="20.0sp" android:textColor="#ff000000" android:gravity="center" android:background="@drawable/round_corners_bluesky" android:clickable="false" android:layout_width="fill_parent" android:layout_height="45.0dip" android:text="5-Metal halide " />
                <ImageView android:background="@drawable/lamp5" android:clickable="false" android:layout_width="fill_parent" android:layout_height="240.0dip" android:layout_marginTop="5.0dip" android:scaleType="fitXY" />
                <TextView android:textSize="12.0sp" android:textColor="#ff000000" android:background="@drawable/round_corners_white" android:padding="10.0dip" android:clickable="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:layout_marginBottom="10.0dip" android:text="A metal-halide lamp is an electric lamp that produces light by an electric arc through a gaseous mixture of vaporized mercury and metal halides[1][2] (compounds of metals with bromine or iodine). It is a type of high-intensity discharge (HID) gas discharge lamp.[1] Developed in the 1960s, they are similar to mercury vapor lamps,[1] but contain additional metal halide compounds in the quartz arc tube, which improve the efficiency and color rendition of the light. The most common metal halide compound used is sodium iodide. Once the arc tube reaches its running temperature, the sodium dissociates from the iodine, adding orange and reds to the lamp's spectrum from the sodium D line as the metal ionizes. As a result, metal-halide lamps have high luminous efficiency of around 75 - 100 lumens per watt,[2] which is about twice that of mercury vapor lights and 3 to 5 times that of incandescent lights[1] and produce an intense white light. Lamp life is 6,000 to 15,000 hours.[2][3] As one of the most efficient sources of high CRI white light, metal halides as of 2005 were the fastest growing segment of the lighting industry.[1] They are used for wide area overhead lighting[2] of commercial, industrial, and public spaces, such as parking lots, sports arenas, factories, and retail stores,[1] as well as residential security lighting and automotive headlamps (xenon headlights). " />
            </LinearLayout>
            <LinearLayout android:orientation="vertical" android:background="@drawable/round_corners_blue" android:padding="10.0dip" android:paddingTop="20.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20.0dip">
                <TextView android:textSize="20.0sp" android:textColor="#ff000000" android:gravity="center" android:background="@drawable/round_corners_bluesky" android:clickable="false" android:layout_width="fill_parent" android:layout_height="45.0dip" android:text="6-High pressure sodium " />
                <ImageView android:background="@drawable/lamp6" android:clickable="false" android:layout_width="fill_parent" android:layout_height="240.0dip" android:layout_marginTop="5.0dip" android:scaleType="fitXY" />
                <TextView android:textSize="12.0sp" android:textColor="#ff000000" android:background="@drawable/round_corners_white" android:padding="10.0dip" android:clickable="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:layout_marginBottom="10.0dip" android:text="A sodium-vapor lamp is a gas-discharge lamp that uses sodium in an excited state to produce light. There are two varieties of such lamps: low pressure and high pressure. Low-pressure sodium lamps are highly efficient electrical light sources, but their yellow light restricts applications to outdoor lighting such as street lamps.[1] High-pressure sodium lamps have a broader spectrum of light than the low-pressure lamps, but still poorer color rendering than other types of lamps.[2] Low-pressure sodium lamps only give monochromatic yellow light and so inhibit color vision at night. " />
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

我的布局有什么问题吗?

1 个答案:

答案 0 :(得分:0)

在主要的Linearlayout中设置方向。因为您在父级中使用Linearlayout,其默认方向是水平的,因此您必须设置它

android:orientation="vertical"