Android:使用TextView项目在GridView中重叠

时间:2015-10-02 19:51:50

标签: java android gridview textview overlapping

我希望获得一个类似于“Google Keep”所代表的视图(您可以看到所有注释) - 我遇到的问题是我的注释过于如此处所示。 http://pl.tinypic.com/r/vwtvtv/8 第3项与第1项完全结合。这是我的第一个应用程序,所以如果你需要可以优化的话,请随时说出来。

1.Overlapping - 我正在尝试使用RecycleView,因为我认为它在“Google Keep”中使用,但在兼容性方面存在问题,在添加依赖项时(从https://developer.android.com/training/material/lists-cards.html复制)我看到一些复杂的修复,但对于它就像那样工作我们需要等待谷歌重新定位新库以支持更新的版本吗?

dependencies {
    ...
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.android.support:recyclerview-v7:21.0.+'
}

的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "radroid.droid_note"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'

}

FragmentMain.class

public class FragmentMain extends Fragment implements LoaderManager.LoaderCallbacks <Cursor> {

    public static final int LOADER_ID = 1;

    SimpleCursorAdapter simpleCursorAdapter;



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_main, container, false);



        getLoaderManager().initLoader(LOADER_ID, null, this);

        final String[] mFromColumns = {NoteDbContract.NoteEntry.NOTE_COLUMN};
        final int[] mToLayout = {R.id.text_view_grid_item};

        simpleCursorAdapter = new SimpleCursorAdapter(rootView.getContext(), R.layout.grid_item_main, null, mFromColumns, mToLayout, 0);

        GridView gridView = (GridView) rootView.findViewById(R.id.grid_view_fragment_main);

        gridView.setAdapter(simpleCursorAdapter);


        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Cursor cursor = (Cursor) simpleCursorAdapter.getItem(position);
                String note = cursor.getString(cursor.getColumnIndex(NoteDbContract.NoteEntry.NOTE_COLUMN));
                Intent intent = new Intent(getActivity(), EditActivity.class).putExtra(Intent.EXTRA_TEXT, note);
                intent.putExtra("row_id", simpleCursorAdapter.getItemId(position));
                intent.putExtra("mod_date", cursor.getString(cursor.getColumnIndex(NoteDbContract.NoteEntry.MOD_DATE_COLUMN)));
                startActivity(intent);
            }
        });

        registerForContextMenu(gridView);
        return rootView;
    }

fragment_main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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"
              android:paddingLeft="@dimen/activity_horizontal_margin"
              android:paddingRight="@dimen/activity_horizontal_margin"
              android:paddingTop="@dimen/activity_vertical_margin"
              android:paddingBottom="@dimen/activity_vertical_margin"
              android:orientation="vertical"


              tools:context=".MainActivity">
<GridView
          android:layout_width="match_parent"
          android:layout_height="40dp"
          android:verticalSpacing="15dp"
          android:horizontalSpacing="15dp"
          android:numColumns="2"
          android:id="@+id/grid_view_fragment_main"
          android:layout_weight = "0.9"
          android:smoothScrollbar="true"
          android:stretchMode="columnWidth"

    >

</GridView>

<Button
android:id="@+id/createNoteButton"
android:text="@string/create_note_button"
android:minHeight="15dp"
android:layout_width="150dp"
android:layout_height="15dp"
android:layout_weight = "0.1"
android:layout_gravity="end"
android:elevation="12dp"
android:backgroundTint="@android:color/white"
android:textColor="#455A64"

    />


</LinearLayout>

grid_item.xml

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

          android:id="@+id/text_view_grid_item"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:textColor="@android:color/black"
          android:background="@android:color/white"
          android:text="TEST"
          android:elevation="2dp"
          android:padding="6dp"
          android:maxLines="4"
          android:ellipsize="end"
          android:maxWidth="200dp"
          android:maxHeight="200dp"

    >

</TextView>
  1. 我也有滚动的问题我可以将somhow滚动出视图(所有项目消失,我无法看到包括按钮“创建注释”的东西,试图解决它但似乎我无法解决它。

0 个答案:

没有答案