我是android的新手。我正在开发一款应用。我的标题为textView
,内容为horizontal_scroll_view
。现在,当我按下textView
时,我需要horizontal_scroll_view
来弹出标题。
XML布局 -
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingStart="20dp"
android:onClick="DailyUseItems"
android:clickable="true"
android:text="Daily Use Products"
android:textColor="#FFFFFF"
android:textSize="24sp" />
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EEEEEE"
android:id="@+id/daily_use_items"
android:scrollbars="none">
</HorizontalScrollView>
答案 0 :(得分:0)
如果您希望将其显示为弹出窗口,则可以进行自定义对话https://developer.android.com/guide/topics/ui/dialogs.html但是如果您想使HorizontalScrollView不可见并使其在标题点击时可见,您可以设置为xml android:visibility="invisible"
或{{ 1}}然后在java中单击监听器android:visibility="gone"
要使其弹出/向下滑动标题,您需要使用android动画。基于此代码https://gist.github.com/rafali/5146957:
MainActivity.class
horizontalScrollView.setVisibility(View.VISIBLE);
ResizeAnimation.class
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final HorizontalScrollView hsc = (HorizontalScrollView) findViewById(R.id.daily_use_items);
TextView tv = (TextView) findViewById(R.id.header);
hsc.setAlpha(0.0f);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
hsc.animate().alpha(1.0f);
ResizeAnimation resizeAnimation = new ResizeAnimation(hsc,hsc.getHeight());
resizeAnimation.setDuration(600);
hsc.startAnimation(resizeAnimation);
}
});
}
}