gpt4 book ai didi

java - Android 6 上的布局问题。充气机问题?在 Android 5 及更早版本上运行良好

转载 作者:太空宇宙 更新时间:2023-11-04 13:13:27 25 4
gpt4 key购买 nike

试图找出这个布局出了什么问题。该应用程序是客户端的,并实现了许多已弃用/不再维护的库(actionbar sherlock、jess.ui.grid.lib、com.handmark.pultorefresh.library)。在 Android 5 (Nexus 7) 上一切正常,但在 Android 6 (Nexus 5) 上,布局中的图像消失,TextView 可见,但它们最终在屏幕上分散得很远。该 View 在 Eclipse 中看起来不错。如果我将 View 放入独立的应用程序中,它就可以正常工作。不幸的是这个应用程序有点复杂,而且我不是 Android 专家,所以很难调试。因此,我们非常感谢任何帮助。

我知道可能性不大,因为我无法真正提供重现此问题的示例项目,但我希望有人遇到类似的情况并可以提供帮助。

首先是图片:Nexus 7 - Android 5.1.1 好 Nexus 7 - Android 5.1.1

Nexus 5 - Android 6.0 ...一些文本在屏幕下方可见,但没有图像,也不是所有文本。

Nexus 5 - Android 6.0

home_activity_intro.xml [已编辑 - 抱歉粘贴了错误的 XML]

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:orientation="vertical" >

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" >

<ImageButton
android:id="@+id/home_intro_tutorial_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/home_callout_top"
android:contentDescription="@string/home_intro_tutorial_title"/>

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:text="@string/home_intro_tutorial_title"
android:textAppearance="?android:attr/textAppearanceLarge" />

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_gravity="center_horizontal|bottom">

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:src="@drawable/generic_blank_btn_up" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="5dp"
android:text="@string/home_intro_tutorial_sub_title"
android:textAppearance="?android:attr/textAppearanceMedium" />
</FrameLayout>
</FrameLayout>

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

<ImageButton
android:id="@+id/home_intro_tutorial_find_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/home_callout_find_and_follow" />

<TextView
android:id="@+id/followCalloutTitle"
style="@style/calloutTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="105dp"
android:layout_marginLeft="105dp"
android:text="@string/home_intro_find_title" />

<TextView
android:id="@+id/followCalloutSubTitle"
style="@style/calloutSubTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@id/followCalloutTitle"
android:layout_alignLeft="@id/followCalloutTitle"
android:layout_alignEnd="@id/home_intro_tutorial_find_button"
android:layout_alignRight="@id/home_intro_tutorial_find_button"
android:layout_below="@id/followCalloutTitle"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:text="@string/home_intro_find_sub_title" />
</RelativeLayout>


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

<ImageButton
android:id="@+id/home_intro_share_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/home_callout_share" />

<TextView
android:id="@+id/shareCalloutTitle"
style="@style/calloutTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginLeft="25dp"
android:text="@string/home_intro_share_title" />

<TextView
android:id="@+id/shareCalloutSubTitle"
style="@style/calloutSubTitle"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignStart="@id/shareCalloutTitle"
android:layout_alignLeft="@id/shareCalloutTitle"
android:layout_below="@id/shareCalloutTitle"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:text="@string/home_intro_share_sub_title" />
</RelativeLayout>


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

<ImageButton
android:id="@+id/home_intro_collections_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/home_callout_collections" />

<TextView
android:id="@+id/collectionCalloutTitle"
style="@style/calloutTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="125dp"
android:layout_marginLeft="125dp"
android:text="@string/home_intro_collections_title" />

<TextView
android:id="@+id/collectionCalloutSubTitle"
style="@style/calloutSubTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@id/collectionCalloutTitle"
android:layout_alignLeft="@id/collectionCalloutTitle"
android:layout_alignEnd="@id/home_intro_collections_button"
android:layout_alignRight="@id/home_intro_collections_button"
android:layout_below="@id/collectionCalloutTitle"
android:layout_marginEnd="30dp"
android:layout_marginRight="30dp"
android:text="@string/home_intro_collections_sub_title" />
</RelativeLayout>


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

<ImageButton
android:id="@+id/home_intro_privacy_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/home_callout_privacy" />

<TextView
android:id="@+id/privacyCalloutTitle"
style="@style/calloutTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginLeft="25dp"
android:text="@string/home_intro_privacy_title" />

<TextView
android:id="@+id/privacyCalloutSubTitle"
style="@style/calloutSubTitle"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignStart="@id/privacyCalloutTitle"
android:layout_alignLeft="@id/privacyCalloutTitle"
android:layout_below="@id/privacyCalloutTitle"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:text="@string/home_intro_privacy_sub_title" />
</RelativeLayout>
</LinearLayout>

HomeActivityAdapterIntro.java

package com.shared2you.android.powerslyde.activities.main_activity.home_screen;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;

import com.shared2you.android.powerslyde.R;
import com.shared2you.android.powerslyde.activities.main_activity.BaseActivity;
import com.shared2you.android.powerslyde.activities.main_activity.profile_screen.ProfileEditActivity;
import com.shared2you.android.powerslyde.networkApis.AndroidLog;

/* Adapter for the activities list on the Home Page. When there are 0 memberActivities to display
* the intro row will be displayed.
*/
public class HomeActivityAdapterIntro extends ArrayAdapter<HomeActivityResult> {

private static String TAG = "HomeActivityAdapterIntro";
private final Context context;
private final HomeActivityResult[] values;

public HomeActivityAdapterIntro(Context context, HomeActivityResult[] values) {
super(context, R.layout.left_nav_row, values);
this.context = context;
this.values = values;

String valuesOut = "";
for (int i = 0; i < values.length; i++) {
if (values[i].activityType == HomeActivityResult.kHomeActivityResultIntro)
valuesOut += "kHomeActivityResultIntro";
else if (values[i].activityType == HomeActivityResult.kHomeActivityResultReal)
valuesOut += "kHomeActivityResultReal";
else
valuesOut += "uknown";

if (i < values.length - 1)
valuesOut += ", ";
}

AndroidLog.i(TAG, "constructor -- values count: " + String.valueOf(values.length) + " -- values: " + valuesOut);
}

/*
* Static method, called by object that creates HomeActivityAdapter to get
* the array that should be passed into the HomeActivityAdapter constructor
*/
public static HomeActivityResult[] retrieveIntroValues() {
// TODO: get activity from sqllite
// Right now we are just creating a black HomeActivityResults row and
// setting the type to 'kHomeActivityResultIntro'
HomeActivityResult[] results = new HomeActivityResult[1];
results[0] = new HomeActivityResult(null, HomeActivityResult.kHomeActivityResultIntro);
AndroidLog.i(TAG, "retrieveIntroValues - setting typ to kHomeActivityResultIntro");
return results;

}

/*
* Returns row based on HomeActivityResult.activityType. Can display intro
* row, or activity row. (non-Javadoc)
*
* @see android.widget.ArrayAdapter#getView(int, android.view.View,
* android.view.ViewGroup)
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO: Create and return activity row when appropriate

HomeActivityResult result = values[position];
AndroidLog.i(TAG, "getView -- position: " + String.valueOf(position) + " result.activityType: "
+ ((result.activityType == HomeActivityResult.kHomeActivityResultIntro) ? "intro" : "real activity"));
View rowView = null;
if (result.activityType == HomeActivityResult.kHomeActivityResultIntro) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.home_activity_intro, parent, false);

// load youtube tutorial on tutorial button click
final ImageButton tutorialButton = (ImageButton) rowView.findViewById(R.id.home_intro_tutorial_button);
tutorialButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
context.startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=_78yr9R-cCA")));
}
});

final ImageButton findButton = (ImageButton) rowView.findViewById(R.id.home_intro_tutorial_find_button);
findButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
EditText searchText = (EditText) ((Activity) context).findViewById(R.id.searchText);
searchText.requestFocus();
}
});

final ImageButton shareButton = (ImageButton) rowView.findViewById(R.id.home_intro_share_button);
shareButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
BaseActivity baseActivity = (BaseActivity) context;
baseActivity.menu.setContent(baseActivity.shareView);
baseActivity.setupCommon();
baseActivity.shareViewController.setupShareView();
baseActivity.fromHomeIntro = true;
}
});

final ImageButton collectionsButton = (ImageButton) rowView
.findViewById(R.id.home_intro_collections_button);
collectionsButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
BaseActivity baseActivity = (BaseActivity) context;
baseActivity.menu.setContent(baseActivity.collectionsView);
baseActivity.setupCommon();
baseActivity.collectionsViewController.setupCollectionsView();
baseActivity.fromHomeIntro = true;

}
});

final ImageButton privacyButton = (ImageButton) rowView.findViewById(R.id.home_intro_privacy_button);
privacyButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
Intent editIntent = new Intent(context, ProfileEditActivity.class);
context.startActivity(editIntent);
}
});

if (parent == null)
AndroidLog.e(TAG, "Parent is null");
else
AndroidLog.i(TAG, "Parent is not null - parent class is: " + parent.getClass().getName());

} else {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.home_activity_intro, parent, false);
}
return rowView;
}
}

最佳答案

我在 Android 6.0 中遇到了几乎相同的问题,同时在 Linearlayout 中有一些 subview 。我将 Linearlayout 更改为 android.support.v7.widget.LinearLayoutCompat,它在 Android 6.0 及其以下版本上运行良好。

希望这对您有帮助!

关于java - Android 6 上的布局问题。充气机问题?在 Android 5 及更早版本上运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33751064/

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