这是我的代码:
public class ScoreFragment extends Fragment {
public static final String TAG ="ScoreFragment";
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
Log.d(TAG, "onAttach");
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(savedInstanceState==null)
{
Log.d(TAG,"onCreate FIRST TIME");
}
else
{
Log.d(TAG,"onCreate SUBSEQUENT TIME");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater,container,savedInstanceState);
final View v = inflater.inflate(R.layout.score_collection, container, false);
final TextView sliderText = (TextView) v.findViewById(R.id.score_number);
sliderText.setTextSize(48);
//TODO: Find solution to find known bug in Android
/* ActionBar actionBar = ((ActionBarActivity) getActivity()).getSupportActionBar();
actionBar.hide();*/
SeekBar seekbar = (SeekBar) v.findViewById(R.id.seekBar);
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
sliderText.setText("" + progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
Log.d(TAG,"onCreateView");
return inflater.inflate(R.layout.score_collection, container, false);
}
seekBar 显示,但它不会增加或在我的视图中显示任何文本。
以下是我在视图中的设置方式(在 RelativeLayout 内):
<SeekBar
android:layout_width="300sp"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:progress="0"
android:max="10"
android:minHeight="30sp"
android:maxHeight="30sp"
android:layout_below="@+id/score_number"
android:layout_centerHorizontal="true"/>
在我将它放入 Fragment 之前它实际上是有效的,所以我认为它与它在 Fragment 中有关,但我不完全确定。
它假设以 1 递增,范围为 0 到 10。