【问题标题】:ScrollView not displaying all Elements of LinearLayoutScrollView 不显示 LinearLayout 的所有元素
【发布时间】:2016-01-01 03:15:30
【问题描述】:

我的 ScrollView 正在切断我的 LinearLayout 的一些元素,我检查了边距和所有内容,但我不确定为什么会发生这种情况。最后一个卡片视图的底部在纵向被切断,在横向被切断更多。 帮助将不胜感激,谢谢!

<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="wrap_content"
tools:context="com.example.jesse.apbiologystudyappv2.NaturalSelectionActivity$PlaceholderFragment">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        card_view:cardElevation="8dp"
        card_view:cardBackgroundColor="@color/cardview_light_background">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:text="• According to Darwin’s theory of natural selection, competition for limited resources results in differential survival. Individuals with more favorable phenotypes are more likely to survive and produce more offspring, thus passing traits to subsequent generations. It's important to remember that natural selection acts on PHENOTYPES, and individuals with phenotypic advantages will prevail.
• Evolutionary fitness is measured by reproductive success. The most fit individuals have the highest reproductive success.
• Genetic variation and mutation play roles in natural selection. A diverse gene pool is important for the survival of a species in a changing environment.
• Environments can be more or less stable or fluctuating, and this affects evolutionary rate and direction; divergent genetic variations can be selected in each generation.
• An adaptation is a genetic variation that is favored by selection and is manifested as a phenotypic trait that provides an advantage to an organism in a particular environment.
• In addition to natural selection, chance and random events can influence the evolutionary process, ESPECIALLY for small populations.
• Conditions for a population or an allele to be in Hardy-Weinberg equilibrium are: (1) a large population size, (2) absence of migration, (3) no net mutations, (4) random mating and (5) absence of selection. These conditions are seldom met in real populations.
• Mathematical approaches are used to calculate changes in allele frequency, providing evidence for the occurrence of evolution in a population."
            android:textColor="@color/colorPrimaryText"
            android:textSize="16dp"
            android:typeface="sans" />
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        card_view:cardElevation="8dp"
        card_view:cardBackgroundColor="@color/cardview_light_background">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="8dp"
                android:text="Hardy Weinberg Principle is as follows:"
                android:textColor="@color/colorPrimaryText"
                android:textAlignment="center"
                android:textSize="24dp"
                android:typeface="sans" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/hardy_weinberg" />
        </LinearLayout>
    </android.support.v7.widget.CardView>
    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        card_view:cardElevation="8dp"
        card_view:cardBackgroundColor="@color/cardview_light_background">


        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:text="• Environments change and act as selective mechanisms on population. For example, Dark Colored moths have risen in population size in industrious cities because smog induced by industry better camouflages dark moths compared to white moths.
• Phenotypic variations are not directed by the environment but occur through random changes in the DNA and through new gene combinations.
• Some phenotypic variations significantly increase or decrease the fitness of the organism and the population. Sickle cell anemia, for example decreases the fitness of humans who are affected.
• Humans impact variation in other species. For example, artificial selection has favored large fruits for consumption.
• Genetic drift is a nonselective process occurring in small populations, in which allele frequencies change as alleles exit and enter the population's gene pool through death, migration, etc.
• Reduction of genetic variation within a given population can increase the differences between populations of the same species.
• Scientific evidence of biological evolution uses information from geographical, geological, physical, chemical and mathematical applications.
• Molecular, morphological and genetic information of existing adn extinct organisms add to our understanding of evolution. For example, the fossil record, relationships within phylogenetic trees, homologous and vestigial structures, the rate of decay of isotopes, etc."
            android:textColor="@color/colorPrimaryText"
            android:textSize="16dp"
            android:typeface="sans" />

    </android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>

【问题讨论】:

  • 将此属性添加到您的 ScrollView:android:fillViewport="true" 并让它在两个维度上都为 fill_parent。此外,这是一个常见的问题场景,请在发布新问题之前尝试搜索类似问题。
  • 对不起@Skynet,它没用。还是同样的问题。
  • 将 PaddingBottom 赋予 LinearLayout。
  • 完美运行,谢谢

标签: android android-layout android-linearlayout android-xml android-scrollview


【解决方案1】:

仅从滚动子项中删除 android:layout_gravity="center"

【讨论】:

    【解决方案2】:

    首先尝试在线性布局中添加底部填充,如果不起作用,则将线性布局替换为相对布局。

    【讨论】:

      【解决方案3】:

      将此添加到您的 CardView 元素中:

      app:cardUseCompatPadding="true"
      

      【讨论】:

      • 我试过card_view:cardUseCompatPadding="true",不幸的是它没有用。而且,实际上我正在 6.0.1 设备上进行测试,所以这应该不是问题。
      【解决方案4】:

      在LinearLayout中设置内边距

      android:padding="5dp"
      

      【讨论】:

        【解决方案5】:

        我的 LinearLayout 顶部内边距为 50dp

         <LinearLayout
                    android:id="@+id/linearLayout"
                    android:paddingTop="50dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" />
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-11-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多