我在我的应用程序中实现this library以完成水平选择器视图我认为我正确地遵循它所要求的但我不知道为什么它的显示任何东西(小部件在这里,但它完全透明)这是我实现这个的方式:
mainActivity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="pb.monthpicker.MainActivity"
tools:showIn="@layout/activity_main">
<com.wefika.horizontalpicker.HorizontalPicker
xmlns:picker="http://schemas.android.com/apk/lib/com.wefika.horizontalpicker"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/colorPrimaryDark"
android:textSize="@dimen/textSize"
android:ellipsize="start"
android:marqueeRepeatLimit="-1"
android:id="@+id/month_picker"
picker:values="@array/values"
picker:dividerSize="@dimen/itemPadding"
picker:sideItems="@integer/sideItems"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
这是值:
// value of sideItems
`<integer name="sideItems">3</integer>`
// value of text size:
<dimen name="textSize">16dp</dimen>
//value of padding:
<dimen name="itemPadding">8dp</dimen>
// value of array
<string-array name="values">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
</string-array>
// build.grade
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "pb.monthpicker"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.wefika:horizontal-picker:+'
}
谁知道你做错了什么?任何指导对我都有帮助,谢谢:)
答案 0 :(得分:1)
替换您的gradle文件
compile 'com.wefika:horizontal-picker:+
带
compile 'com.wefika:horizontal-picker:1.1.0'
尝试使用此布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.wefika.horizontalpicker.example.MainActivity">
<com.wefika.horizontalpicker.HorizontalPicker
android:id="@+id/picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_blue_dark"
android:textSize="22sp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:ellipsize="marquee"
android:marqueeRepeatLimit="2"
android:focusable="true"
android:focusableInTouchMode="true"
app:values="@array/values"
app:dividerSize="10dp"
app:sideItems="1"/>
</RelativeLayout>