質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Q&A

0回答

310閲覧

mindmapを作りたい

Moai101

総合スコア20

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

0グッド

0クリップ

投稿2017/10/24 14:19

現在android studioで以下のコード(https://github.com/qq273681448/Mindmap)を参考にしてロジカルツリーのアプリを作っています。今私が解決したい問題としましては、
1、clickしたボタンに打ったテキストを表示できるようにする。
2、ボタンをクリックした場合、ランダムで次のボタンが出てくるのでクリックした数だけボタンが出てくるようにする。
という内容です。以下にコードを載せますのでどうかご協力おねがいします。

public void drawbutton(int button_y, int button_x, int line_x, final int tree_current, final nodechild[] nc, String nodeid) { // 存储线的起点y坐标 int line_y = button_y; // 这个只是为了区分业务中偶数层button宽度为300,齐数层为200 button_x = tree_current % 2 == 1 ? button_x : button_x - 100; // 得到下一层级需要绘制的数量 int num = 1; if (tree_current != 1) num = nc.length;// 下一层个数 // 得到下一级第一个按钮的y坐标 button_y = button_y - (num - 1) * bt_width / 2; if (button_y < tree_xnum[tree_current]) { button_y = tree_xnum[tree_current] + 100; } // 移动当前布局到页面中心 if (tree_current > 2) hv.scrollTo(button_x - 400, button_y - 100); if (tree_xnum[tree_current] < button_y + 200 + (num - 1) * bt_width) tree_xnum[tree_current] = button_y + 200 + (num - 1) * bt_width; // 存储下一级首个button坐标 final int button_y_f = button_y; final int button_x_f = button_x; for (int i = 0; i < num; i++) { final int bt_paly_y = bt_width; int bt_w = tree_current % 2 == 0 ? bt_width : 200; int bt_h = 200; // 定义及设置button属性 bt[i] = new Button(this); if (tree_current % 2 != 0) { bt[i].setBackgroundResource(R.drawable.allokbutton); } else { bt[i].setBackgroundResource(R.drawable.button33); } bt[i].setTextColor(Color.WHITE); bt[i].setTextSize(15 - (int) Math.sqrt(nc[i].getName().length() - 1)); bt[i].setText(nc[i].getName()); // 定义及设置出场动画 final String nc_id = nc[i].getId(); ScaleAnimation animation = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setInterpolator(new BounceInterpolator()); animation.setStartOffset(tree_current == 1 ? 1050 : 50);// 动画秒数。 animation.setFillAfter(true); animation.setDuration(700); bt[i].startAnimation(animation); final int i1 = i; // 设置监听 bt[i].setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { LayoutInflater inflater = LayoutInflater.from(MainActivity.this); View view = inflater.inflate(R.layout.dialog_edit_el, null); final EditText editText= (EditText)view.findViewById(R.id.etEditEl); new AlertDialog.Builder(MainActivity.this) .setTitle("Hello, AlertDialog!") .setView(view) .setPositiveButton( "Close", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String text = editText.getText().toString(); bt[1].setText(text); } }) .show(); if (model) mstack.pop(tree_current); // 防止多次点击,偷懒的解决办法 if (((Button)v).getHint() != null) { Toast.makeText(getApplicationContext(), ((Button)v).getText(), Toast.LENGTH_LONG).show(); return; } ((Button)v).setHint("1"); insertLayout.setEnabled(false); int w = button_y_f + i1 * bt_paly_y; int h = button_x_f + bt_paly_y / 2 * 3; getRemoteInfo(w, h, button_y_f + i1 * bt_paly_y, button_x_f, tree_current + 1, nc_id, nc[i1].getButeid()); } }); // 把button通过布局add到页面里 layoutParams[i] = new RelativeLayout.LayoutParams(bt_w, bt_h); layoutParams[i].topMargin = button_y + i * bt_paly_y; layoutParams[i].leftMargin = button_x; insertLayout.addView(bt[i], layoutParams[i]); // 把线绘制到页面里 if (tree_current != 1) { if (button_y + 100 + i * 300 - (line_y + 100) >= 0) {//为了优化内存,也是醉了 view = new DrawGeometryView(this, 50, 50, button_x + 100 - (line_x + bt_paly_y) + 50 + (tree_current % 2 == 0 ? 100 : 0), button_y + 100 + i * 300 - (line_y + 100) + 50, nc[i].getButetype()); layoutParams1[i] = new RelativeLayout.LayoutParams(Math.abs(line_x - button_x) + 500, 100 + button_y + i * 300 - line_y); view.invalidate(); layoutParams1[i].topMargin = (line_y + 100) - 50;// line_y-600;//Math.min(line_y+100,button_y+100 layoutParams1[i].leftMargin = (line_x + bt_paly_y) - 50;// line_x+300; if (tree_current % 2 == 0) layoutParams1[i].leftMargin -= 100; insertLayout.addView(view, layoutParams1[i]); } else { view = new DrawGeometryView(this, 50, -(button_y + 100 + i * 300 - (line_y + 100)) + 50, button_x - line_x - 150 + (tree_current % 2 == 0 ? 100 : 0), 50, nc[i].getButetype()); layoutParams1[i] = new RelativeLayout.LayoutParams(Math.abs(line_x - button_x) + 500, 100 + Math.abs(button_y + i * 300 - line_y)); view.invalidate(); layoutParams1[i].topMargin = (button_y + 100 + i * 300) - 50;// line_y-600;//Math.min(line_y+100,button_y+100 layoutParams1[i].leftMargin = (line_x + bt_paly_y) - 50;// line_x+300; if (tree_current % 2 == 0) layoutParams1[i].leftMargin -= 100; insertLayout.addView(view, layoutParams1[i]); } // line入栈 mstack.push(view, tree_current); } // button入栈 mstack.push(bt[i], tree_current); } } public synchronized void getRemoteInfo(int paly_y, int paly_x, int ppaly_y, int ppaly_x, int tree_h, String nodeid, String buteid) { int n = 1; Random random = new Random(); n = random.nextInt(4) + 1; nodechild[] nc = new nodechild[n]; for (int i = 0; i < n; i++) { nc[i] = new nodechild("1", "你好"); } drawbutton(paly_y, paly_x, ppaly_x, tree_h, nc, nodeid); } public class Mystack { View[] v = new View[1500]; int[] treehigh = new int[1500]; int size = 0; public void push(View view, int treecurrent) { size++; v[size] = view; treehigh[size] = treecurrent; } public void pop(int treecurrent) { while (treehigh[size] > treecurrent && size > 0) { if (size > 0) insertLayout.removeView(v[size]); size--; } for (int j = 49; j > treecurrent; j--) {//树高清0 tree_xnum[j] = 0; } for (int x = size; x > 0; x--) { if (treehigh[x] > treecurrent) { insertLayout.removeView(v[x]); }//修复栈顶元素被前一层树元素占用bug,但是会浪费少量内存,考虑到内存很小,暂时不优化吧。 if (treehigh[x] == treecurrent) { try { ((Button) v[x]).setHint(null); } catch (Exception e) { e.printStackTrace(); } } } } } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問