# HorizontalPicker
**Repository Path**: HarmonyOS-tpc/HorizontalPicker
## Basic Information
- **Project Name**: HorizontalPicker
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2021-04-01
- **Last Updated**: 2023-04-17
## Categories & Tags
**Categories**: harmonyos-selector
**Tags**: None
## README
# Demo
# USED:
```
dependencies{
implementation 'io.openharmony.tpc.thirdlib:HorizontalPicker:1.0.1'
}
```
```xml
```
```java
HorizontalPicker hpText = (HorizontalPicker)findComponentById(ResourceTable.Id_hpText);
HorizontalPicker hpImage = (HorizontalPicker)findComponentById(ResourceTable.Id_hpImage);
HorizontalPicker.OnSelectionChangeListener listener = new HorizontalPicker.OnSelectionChangeListener() {
@Override
public void onItemSelect(HorizontalPicker picker, int index) {
//picker选择的index
}
};
List textItems = new ArrayList<>();
for(int i=1;i<=4;i++){
textItems.add(new HorizontalPicker.TextItem("S"+i));
}
hpText.setItems(textItems,3);
List imageItems = new ArrayList<>();
imageItems.add(new HorizontalPicker.DrawableItem(ResourceTable.Media_icon_led));
imageItems.add(new HorizontalPicker.DrawableItem(ResourceTable.Media_icon_ir));
hpImage.setItems(imageItems);
hpImage.setSelectedIndex(0);
hpText.setChangeListener(listener);
hpImage.setChangeListener(listener);
```
# API:
## class:HorizontalPicker
**public void setItems(List items)**
- description: set items
**public void setItems(List items, int selectedIndex)**
- description: set items and frist selected index
**public List getItems()**
- description: get items
**public void setSelectedIndex(int selectedIndex)**
- description: set selected item with index
**public PickerItem getSelectedItem()**
- description: get selected item
**public Element getBackground()**
- description: get default background element
**public Element getBackgroundSelected()**
- description: get selected background element
**public void setBackground(int normal, int selected)**
- description: set defualt background and selected background with xml ID
**public int getColorNormal()**
- description: get defualt color
**public int getColorSelected()**
- description: get selected color
**public void setColorSelector(int normal, int selected)**
- description: set default color and selected color
**public int getTextSize()**
- description: get text size
**public void setTextSize(int textSize)**
- description: set text size
**public int getItemWidth()**
- description: get item width
**public void setItemWidth(int itemWidth)**
- description: set item width
**public int getItemMargin()**
- description: get item margin
**public void setItemMargin(int itemMargin)**
- description: set item margin
**public int getItemHeight()**
- description: get item height
**public void setItemHeight(int itemHeight)**
- description: set item height
**public OnSelectionChangeListener getChangeListener()**
- description: get selected change listener
**public void setChangeListener(OnSelectionChangeListener changeListener)**
- description: set selected change listener
# AttrSet:
|name|format|description|
|:---:|:---:|:---:|
| backgroundNormal | element | get defualt background element
| backgroundSelected | element | get selected background element
| textColor | color | set default text color
| textColorSelected | color | set selected text color
| textSize | dimension | set text size
| itemHeight | dimension | set item height
| itemWidth | dimension | set item width
| itemMargin | dimension | set item margin
## LICENSE :
```
MIT License
Copyright (c) 2017 GoodieBag
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```