gpt4 book ai didi

java - ScrollView 不工作。我应该怎么办?

转载 作者:搜寻专家 更新时间:2023-11-01 09:20:09 24 4
gpt4 key购买 nike

如何在我的 Android 应用中滚动?

我已经尝试过 Scrollview,但它不起作用。

所以这是我的 MainActivity:

package com.example.myapplication2;

import android.content.DialogInterface;
import android.content.Intent;
import android.icu.text.IDNA;
import android.nfc.Tag;
import android.os.PersistableBundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;

import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import static com.example.myapplication2.R.id.*;

public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {

private boolean loadFragment(Fragment fragment){
if(fragment!=null){
getSupportFragmentManager()
.beginTransaction()
.replace(fragment_container, fragment)
.commit();
return true;
}
return false;
}

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

BottomNavigationView navigation = findViewById(R.id.bottomnav);
navigation.setOnNavigationItemSelectedListener(this);

getSupportFragmentManager().beginTransaction().replace(fragment_container, new Home_Screen()).commit();
}


@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
Fragment fragment = null;

switch(menuItem.getItemId()){
case kontakt:
break;

case Termine:
fragment = new TermineFragment();
break;

case wilkommen:
fragment = new Home_Screen();
break;
}

return loadFragment(fragment);
}
}

这是我的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/darkgrey">

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Termine"
android:textSize="30sp"
android:textColor="@color/colorAccent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
></TextView>

<android.support.v7.widget.CardView

android:layout_width="match_parent"
android:layout_height="173dp"
app:cardCornerRadius="8dp"
android:layout_marginTop="80dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>

<Button
android:text="Mehr infos"
android:layout_width="120dp"
android:layout_height="35dp"
android:id="@+id/button1"
android:layout_weight="1"
android:layout_marginTop="130dp"
android:layout_marginRight="170dp"
/>

<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/maincolor"

>
</LinearLayout>

<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="HPI - 29.06.19"
android:textSize="24dp"
/>

<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="Sitzung: H-E.51"
android:textSize="16dp"
android:layout_marginTop="40dp"

/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="Juni22, 2019"
android:textSize="16dp"
android:layout_marginTop="40dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="270dp"
/>
</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView

android:layout_width="match_parent"
android:layout_height="173dp"
app:cardCornerRadius="8dp"
android:layout_marginTop="270dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>

<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/colorPrimaryDark"

/>

<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="HPI - 13.07.19"
android:textSize="24dp"
/>

<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="Sitzung: H-E.51"
android:textSize="16dp"
android:layout_marginTop="40dp"

/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="July13, 2019"
android:textSize="16dp"
android:layout_marginTop="40dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="270dp"

/>
</android.support.v7.widget.CardView>
</RelativeLayout>

我该怎么办?我想在我的 ScrollView 中使用这些卡片 View 。

最佳答案

将您的 XML 布局代码替换为以下代码。另外,请注意,您的两张卡之间的 topMargin 数量似乎很尴尬,不确定这是不是有意为之,但截至目前,您的两张卡之间存在巨大差距:

<?xml version="1.0" encoding="utf-8"?>
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/darkgrey">

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Termine"
android:textSize="30sp"
android:textColor="@color/colorAccent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />

<android.support.v7.widget.CardView

android:layout_width="match_parent"
android:layout_height="173dp"
app:cardCornerRadius="8dp"
android:layout_marginTop="80dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>

<Button
android:text="Mehr infos"
android:layout_width="120dp"
android:layout_height="35dp"
android:id="@+id/button1"
android:layout_weight="1"
android:layout_marginTop="130dp"
android:layout_marginRight="170dp" />


<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/maincolor">

</LinearLayout>

<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="HPI - 29.06.19"
android:textSize="24dp" />

<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="Sitzung: H-E.51"
android:textSize="16dp"
android:layout_marginTop="40dp"/>

<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="Juni22, 2019"
android:textSize="16dp"
android:layout_marginTop="40dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="270dp" />

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

<android.support.v7.widget.CardView

android:layout_width="match_parent"
android:layout_height="173dp"
app:cardCornerRadius="8dp"
android:layout_marginTop="270dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>

<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/colorPrimaryDark"

/>

<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="HPI - 13.07.19"
android:textSize="24dp"
/>

<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="Sitzung: H-E.51"
android:textSize="16dp"
android:layout_marginTop="40dp"

/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:text="July13, 2019"
android:textSize="16dp"
android:layout_marginTop="40dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="270dp"

/>

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

</LinearLayout>

</ScrollView>

</RelativeLayout>

关于java - ScrollView 不工作。我应该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56814205/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com