Wieso ändern sich die Position der Elemente am Handy?

Hey Leute,

ich habe ein kleines Preoblem und zwar die Positionen der Elemente im Android Studio enspricht nicht der am Handy also am Handy werden sie komplett anders angeordernt und nicht wie ich sie im Android Studio positioniert hatte.

Z.B. der Button sollte oben sein und nicht unten!

Hat jemand vielleicht eine Idee voran es liegen könnte?

Danke im Voraus


  

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="158dp"
        android:layout_marginBottom="274dp"
        android:text="@string/button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>



---------------------------manifest------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Test">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


-----------------gradle-------------------------
plugins {
    id 'com.android.application'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.test"
        minSdk 21
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Bild zum Beitrag
programmieren, Design, Java, Android App, Android Studio
Android Studio App stürzt ab nach klick auf Button?

Hallo,

ich habe eine Android Studio Applikation mit einer Bottom Navigation bar, bei welcher unter dem Reiter "Profile" ein User hinzugefügt werden soll. Wenn ich dort auf "Add User" klick stürzt die App allerdings ab, in der Version ohne Navigationsbar funktioniert das allerdings einwand frei. Vielleicht kann mir jedmand helfen, den Fehler zu finden.

Hier ist die UI von Profile:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout ...
    ...
    <Button
        android:id="@+id/btAddUser"
        ...
        android:text="Add User"
        android:onClick="onAddUser"
        />

</LinearLayout>

Hier die UI der BottomBar:

<?xml version="1.0" encoding="utf-8"?>
<...
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/fragment_container"
        >  
...
 app:menu="@menu/bottom_navigation"/>
    </FrameLayout>

Die Klasse zur BottomBar:

package com.example.bottomnav;
import ...
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

BottomNavigationView bottomNavigation = findViewById(R.id.bottom_navigation);    bottomNavigation.setOnNavigationItemSelectedListener(navListener);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
...
private BottomNavigationView.OnNavigationItemSelectedListener navListener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull @NotNull MenuItem item) {
Fragment selectedFragment = null;
switch (item.getItemId())
{
case R.id.nav_projects:
selectedFragment = new ...
ProfileFragment();
break;
}
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
selectedFragment).commit();
return true;
}};}

Hier der Code zum Profil hinzufügen:

@Nullable
@org.jetbrains.annotations.Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_profile, container, false);
}

public
class MyActivity extends AppCompatActivity {
    ...

    Button btAddUser;
...

    Boolean isAdmin = Boolean.FALSE;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_profile);
       ...
        btAddUser = findViewById(R.id.btAddUser);

        btAddUser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {onAddUser(btAddUser);}

    public void onAddUser(View view) {
...

Computer, Java, Android, Informatik, XML, Progamm, Android Studio
Flutter-Future<List> als List zurück geben?

Heeeeey Leute,

Ich rufe eine Liste aus der Datenbank ab und will daraus eine Liste auf der App visualisieren.

Aber in einer async Funktion kann ich keine liste zurück geben.
Wie bekomme ich die Liste jetzt in meinen build.

Code sieht so aus

  void missionEntries()async{
    final Future<List>mission=DBManagement().getAll();
    List missions=await mission.then((value) => null);
  }

  @override
  Widget build(BuildContext context) {
    missionEntries();
    return Expanded(
      child: Container(
        child: ListView.builder(
          itemCount: missions.length,
          itemBuilder: (context, index) {
            return GestureDetector(
              onLongPress: ()=>print("Eintrag bearbeiten!"),
              onTap: ()=>print("Eintrag einsehen!"),
              child: Card(
                child: Row(
                  children: <Widget>[
                    Expanded(
                      child: Text(
                        missions[index]["num"],
                        textAlign: TextAlign.center,
                      ),
                    ),
                    Expanded(
                      child: Text(missions[index]["location"]),
                    ),
                    Expanded(
                      child: Text(missions[index]["date"].toString()),
                    ),
                    Expanded(
                      child: Text(missions[index]["time"].toString()),
                    ),
                    Expanded(
                      child: IconButton(
                        icon: Icon(Icons.delete),
                        onPressed: ()=>print("löschen")
                      )
                    ),
                  ],
                ),
              ),
            );
          }
        ),
      ),
    );
  }

und missionEntries(); müsste eigentlich zu

List missions=missionEntries() werden weil ich die missions liste

ein paar zeilen weiter im ListView.builder brauche.

Hoffe Ihr könnt mir helfen.

programmieren, Scripten, Visual Studio, Flutter, Android Studio

Meistgelesene Beiträge zum Thema Android Studio